CS456 Assignment 1
CS456 Assignment 1
1 Assignment ObjecPve
The goal of this assignment is to gain experience with both TCP and UDP socket programming
in a client-server environment (Figure 1). You will use Python or any other programming
language to design and implement a client program (client) and a server program (server)
to communicate between themselves.
2 Assignment SpecificaPons
2.1 Summary
In this assignment, the client will send requests to the server to reverse strings (taken as a
command line input) over the network using sockets.
This assignment uses a two-stage communicaPon process. In the negoPaPon stage, the client
and the server negoPate on a random port (<r_port>) for later use through a fixed negoPaPon
port (<n_port>) of the server. Later in the transacPon stage, the client connects to the server
through the selected random port for actual data transfer.
2.2 Signaling
The signaling in this project is done in two stages as shown in Figure 2.
Stage 1. Nego+a+on using TCP sockets: In this stage, the client creates a TCP connecPon with
the server using <server_address> as the server address and <n_port> as the negoPaPon
port on the server (where the server is listening). The client sends a request to get the random
port number from the server where it will send the actual request (i.e., the string to be re-
versed). To iniPate this negoPaPon, the client sends a request code (<req_code>), an integer
(e.g., 13), a]er creaPng the TCP connecPon. If the client fails to send the intended <req_code>,
the server closes the TCP connecPon and conPnues listening on <n_port> for subsequent
client requests. Once the server verifies the <req_code>, it replies back with a random port
number <r_port> where it will be listening for the actual request. A]er receiving this <r_-
port>, the client closes the TCP connecPon with the server.
Stage 2. Transac+on using UDP sockets: In this stage, the client creates a UDP socket to the
server in <r_port> and sends the <msg> containing a string. On the other side, the server re-
ceives the string and sends the reversed string back to the client. Once received, the client
prints out the reversed string and exits. Note that the server should conPnue listening on its
<n_port> for subsequent client requests. For simplicity, we assume, there will be only one
client in the system at a Pme. So, the server does not need to handle simultaneous client con-
necPons.
For example, if the negoPaPon port of the server is 52500, then the server should print:
SERVER_PORT=52500
• You can use and adapt the sample codes of TCP/UDP socket programming in Python
slides (last few slides Chapter 2).
• Use port id greater than 1024, since ports 0-1023 are already reserved for different
purposes (e.g., HTTP @ 80, SMTP @ 25)
• If there are problems establishing connecPons, check whether any of the computers
running the server and the client is behind a firewall or not. If yes, allow your programs
to communicate by configuring your firewall so]ware.
• Make sure that the server is running before you run the client.
• Also remember to print the <n_port> where the server will be listening and make sure
that the client is trying to connect to that same port for negoPaPon.
• If both the server and the client are running in the same system, 127.0.0.1 or localhost
can be used as the desPnaPon host address.
• You can use help on network programming from any book or from the Internet, if you
properly refer to the source in your programs. But remember, you cannot share your
program or work with any other student.
4 Procedures
4.1 Due Date
The assignment is due on Friday, October 22, 2021, before midnight (11:59 PM).
4.4 EvaluaPon
Work on this assignment is to be completed individually.
5 AddiPonal Notes:
• You have to ensure that both <n_port> and <r_port> are available. Just selecPng a ran-
dom port does not ensure that the port is not being used by another program.
• All codes must be tested in the linux.student.cs environment prior to submission.
• Run client and server in two different student.cs machines
• Run both client and server in a single student.cs machine
• Make sure that no addiPonal (manual) input is required to run any of the server or client.