Sample Programs

The assignment (and a few lab exercises) for this course are based on network programming. You are given the choice to use either Python, JAVA or C for attempting the assignment and the programming based lab exercises. Decide on which programming language you would use (the one you are most comfortable/proficient with) and practice writing simple network based programs.

We have provided sample TCP and UDP client and server programs written in Python, JAVA and C that you can download and execute (see links at the bottom). This will provide you with a working example of a simple application and will be useful when you start developing your assignment. This is an ECHO program, in which the server echoes back the data, after converting it to Uppercase (i.e. capital letters) to the client. Compile and run these programs in different xterm windows on the same host.

NOTE: please read the programs before executing them to understand what they do.

C Programs

Usage after compiling and assuming that the executables are named TCPServer and TCPClient respectively (for UDP the executables are UDPServer and UDPClient). Execute them in different xterm windows on the same host:

>TCPServer 
>TCPClient 

Once the client is running it will ask for user input. Type a string in lower case. The client should print the corresponding upper case string received from the server.

If you encounter an error message that the port is already in use, change the server port number in both client and server programs (it is currently 1500), someone else may be running the same program at that time. Look for a comment that says //change this port number if required

Java Programs

Usage after compiling and assuming that the executables are named TCPServer and TCPClient respectively (for UDP the executables are UDPServer and UDPClient). Execute them in different xterm windows on the same host:

>java TCPServer 
>java TCPClient 

Once the client is running it will ask for user input. Type a string in lower case. The client should print the corresponding upper case string received from the server.

If you encounter an error message that the port is already in use, change the server port number in both client and server programs (it is currently 6789), someone else may be running the same program at that time. Look for a comment that says /*change above port number if required*/ to make this change.

Python Programs

Usage assuming that the executables are named TCPServer and TCPClient respectively (for UDP the executables are UDPServer and UDPClient). Execute them in different xterm windows on the same host:

>python TCPServer 
>python TCPClient 

Once the client is running it will ask for user input. Type a string in lower case. The client should print the corresponding upper case string received from the server.

If you encounter an error message that the port is already in use, change the server port number in both client and server programs (it is currently 12000), someone else may be running the same program at that time. Look for a comment that says #change this port number if required.

Resources on socket programming

Here are some very useful resources:

C:

Beej's Guide to Network Programming

Sockets Tutorial

Unix Sockets Tutorial

TCP/IP Socket Programming in C

Java

Java Socket Programming (PDF)

Sockets Programming in Java: A tutorial

All about Sockets (by Sun)

Java Networking Tutorial

Python

Python Network Programming

Socket Programming HOWTO

Socket Programming in Python (IBM)

Network Programming in Python

Makefile

Using make and writing Makefiles



Back to top

COMP3331/COMP9331 21T3 (Computer Networks and Applications) is powered by WebCMS3
CRICOS Provider No. 00098G