File: Steve/Courses/2014/s2/its332/source.tex, r3463
This appendix includes example implementation of clients and servers that can exchange data across the Internet. They are implemented in C. There is a TCP version and a UDP version. The source code is quite old (there are newer, better constructs available), and may produce warnings when compiled, however it still executes as intended. The purpose of this code is to show a simple example of using sockets in C to create an Internet client/server application. If you want to create your own application, it is recommended you look for other (better) ways to implement in C.
The source code can be downloaded via http://ict.siit.tu.ac.th/~sgordon/netlab/source/.
On one computer compile the server and then start it. The server takes a port number as a command line argument:
On another computer compile the client and then start it. The client takes the IP address of the server and the port number it uses as command line arguments:
The client prompts for a message. Type in a message and press Enter. The result should be the message being displayed at the server and then the client printing “I got your message”. The client exits, but the server keeps running (other clients can connect).
An example on the client:
And on the server:
On one computer compile the server and then start it. The server takes a port number as a command line argument:
On another computer compile the client and then start it. The client takes the IP address of the server and the port number it uses as command line arguments:
The client prompts for a message. Type in a message and press Enter. The result should be the message being displayed at the server and then the client printing “Got your message”. The client exits, but the server keeps running (other clients can connect).
An example on the client:
And on the server: