The Server.

In this small series I'll show you how to write a simple UDP Client/Server system in a Unix environment using the C language. The server waits data listening on a port specified by the user, if the received data contains ".quit." string the server exits.

Blablablabla……

 

Finally the main function, 

 

First of all I check for the command line argument. the server shall be launched with only one parameter, this parameter will set the port to listen to. the port number shall be > 1023 because Linux reserves port from 1 to 1023. 

Now I create a new UDP socket:

I bind the socket with the port.

infinite loop waiting for data. this loop will end when the server will receive ".quit."

waiting for data

does data contains the quit command?

No. data doesn't contain the quit command

release the socket.

See you later for the Client side,

gg1.

 

 

 

SIMPLE UDP CLIENT/SERVER

Network programming index:

The Server

The Client

Demonizing the Server

The source code