The Client.

The following code contains the implementation for the UDP client application that can send data to the server explained in the previous article.

Blablablabla.

Finally the main function…..

First of all I check for the command line argument. the client shall be launched with at least two parameters, the destination IP address and the port number to which the client will send data, the port number shall be > 1023 because Linux reserves port from 1 to 1023. In addition the client can accept a third argument, if the 3rd argument is present the client will send to the server the string of the 3rd argument (this can be used to send to the server the termination command).

Now I create a new UDP socket

Now I prepare the address to which I want to send data.

memset((char *) &si_server, 0, sizeof(si_server));

If the 3rd argument is present the client sends it to the server

if(argc==4)

Else the client sends NUMBER_OF_PACKETS packets to the server (NUMBER_OF_PACKETS is defined in clientserver.h)

else

Release the socket and exit

SIMPLE UDP CLIENT/SERVER

Network programming index:

The Server

The Client

Demonizing the Server

The source code