Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9044409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:58:48+00:00 2026-06-16T10:58:48+00:00

Good morning, I finished reading Beej’s network programming guide to refresh my memory on

  • 0

Good morning,

I finished reading Beej’s network programming guide to refresh my memory on C networking concepts.

For the next part of the application that I’m building I want the user to be able to connect to their iPhone/iDevice via their web browser using a port, say 8080.

So for testing purposes I tried it on myself, but I get some unexpected issues. I bind a port to the kernel and wait for incoming connections. To simulate a remote user, I go to my web browser and type in localhost:8080

The NSLog and printf() messages I set up throughout the application show that I did connect and I even verified it by showing the IP address of the connecting user, but the client side of the application isn’t behaving as expected. I’m sending HTML to the client in my server code, but nothing shows up. Here’s the code I have so far

- (void) start
{

   struct addrinfo hints ,*res;
   struct sockaddr_storage connectionInfo;

   socklen_t connectionSize;
   memset(&hints,0,sizeof(hints));
   hints.ai_family = AF_INET;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_flags = AI_PASSIVE;
   int status;
   if((status = getaddrinfo(NULL,"8080",&hints,&res) )!= 0)
   {
       NSLog(@"Error inding getaddrinfo..");
       printf("%s",gai_strerror(status));

       return;
   }


   int sockFd = socket(res->ai_family,res->ai_socktype,res->ai_protocol);

   int yes = 1;
   setsockopt(sockFd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int));

   if(sockFd < 0)
   {
       NSLog(@"Error on the socket() call");
       printf("%s",gai_strerror(sockFd));
       freeaddrinfo(res);
       return;
   }

   NSLog(@"Made the socket connection!");

   if(bind(sockFd , res->ai_addr, res->ai_addrlen) < 0)
   {
       NSLog(@"Bind error!");
       freeaddrinfo(res);
       return;


   } 


   if(listen(sockFd,10) < 0)
   {
       NSLog(@"Unable to listen!");
       freeaddrinfo(res);
       return;
   }
   printf("Listening for a connection\n");

   connectionSize = sizeof(connectionInfo);

   int new_fd = accept(sockFd,(struct sockaddr*)&connectionInfo,&connectionSize);

   const char* data = "<html><head><title> hi </title><body><h1> Test</h1> 
     </body></head></html>";
   send(new_fd,data,strlen(data),0);
   if(new_fd < 0)
   {
       NSLog(@"Cannot communicate with the new_fd");
       freeaddrinfo(res);
       printf("%s",gai_strerror(new_fd));
       return;
   }
   NSLog(@"Communication with the new_fd!!!");
   struct sockaddr_in whoAreThey;
   socklen_t size = sizeof(whoAreThey);
   getpeername(new_fd, (struct sockaddr*)&whoAreThey, &size);
   char theirIp[16];
   void* addrPtr = &(whoAreThey.sin_addr);
   inet_ntop(AF_INET, addrPtr, theirIp, sizeof(theirIp));
   NSLog(@"IP Address ");
   printf("%s  Connected\n",theirIp);
   NSLog(@"The data were sent");
   close(sockFd);
   freeaddrinfo(res);





}

and inside my viewDidLoad method I call start as such:

- (void) viewDidLoad
{
      [super viewDidLoad];  
      [self start];

}

Why isn’t the client ( web browser) displaying the HTML? Thanks

Note: I know the data IS Being sent because using telnet localhost 8080 feeds me the HTML

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:58:50+00:00Added an answer on June 16, 2026 at 10:58 am

    You’re not reading the browser’s request. The browser might not read your data unless you fully read the data it sent to you.

    So a recv loop (until there’s no more data from the browser) just before the send should fix your problem.

    EDIT: Final solution was that the response line was not sent to the browser. Offending line is:

    const char* data = "<html><head><title> hi </title></head><body><h1> Test</h1></body></html>";
    

    and should be:

    const char* data = "HTTP/1.0 200 OK\r\n\r\n<html><head><title> hi </title></head><body><h1> Test</h1></body></html>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Morning All, I am developing a new ASP.net MVC web application. Part of
Good Morning SO Campers, I'm interested in developing a social networking site. It will
Good morning, I have mysql queries where I would like to calculate percentage of
Good morning, I am currently developing a java web application that exposes a web
Good Morning, Is it possible to map assembly requests to the version within another
Good Morning. I have two tables, and one references the other. When I insert
Good morning. I've been having this issue for some days and have been lokking
Good morning, I am building a website to act as a Foxpro front end.
Good morning gang. I have a jQuery Datepicker object that is prepoulated using a
Good Morning, I have a very odd error working in adobe flexbuilder 3. Ever

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.