Sample Client-Server Program written in C using TCP socket

¡¡

In this example, a server will convert any letters gotten from a client. For example, if a user at a client machine typed 'abcdefg', the server will convert these characters to 'ABCDEFG'.

To create an executable 'client' and 'server' program, type 'make' at the console. Now, before you run the program, check your machine's hostname by typing 'hostname'. This will give you the hostname that you are in.

In order to run the server, run the program with any arbitrary port number (must be greater than 1024). For example, type 'server 6789' then enter. Then, in another xterm (or another host), run the client program by typing 'client <hostname> 6789'. Then, you will be able to type some characters for an input. (e.g., if you type 'abcabc', then the server will print out 'ABCABC' on the console.)

Examine the sample code as the above carefully and study yourself before you write C/C++ code for our programming project. If you have any questions, please do raise it by using our course mailing list ([email protected]).

¡¡

<Back to Home>

Last Update: 26/10/2005

Hosted by www.Geocities.ws

1