Hello World Tcp Server Using Sockets (2)

Posted By: SecurityTube_Bot
Posted On: Mon 21 Feb 2011
Views: 4952
Share this video:
Share it on Facebook Share it on Twitter Share it on Reddit Share it on Digg Share it on Stumbleupon
Support SecurityTube:


Description: In this video we continue coding our "Hello World" server. We will now encounter the most important API call - accept() ( from a server's perspective ). Accept() allows the server process to accept client connections and process them. We will currently run the server in an infinite loop, so that we can process clients one after the other. The important thing to note here that this server process is not multithreaded and thus can only process a single client at a time. To be able to process multiple clients asynchronous calls such as select() or multithreading will have to be used. Links:

1. Beej's Socket Programming guide

2. Client Server programming using sockets

3. Unix Network Programming

4. Raw Socket programming basics

Tags: programming ,


Comments (1)

jmcboots on Fri 29 Apr 2011

Hello, I am very new to programming. I follow along and all works, but only after I get rid of the printing of the client addr.

For this line:
printf("Sent %d bytes to client : %s\n", sent, inet_ntoa(client.sin_addr));

I get:
HelloServer.c:49: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’

I type client as the sockaddr_in struct:
struct sockaddr_in server, client;

which gets "populated" by the accept:
if((cli = accept(sock, (struct sockaddr *)&client, &len)) == -1)

What am I doing wrong?

Thanks! and great vids!! you need to link to part 2 from part 1 though.

Login to post a comment