Starting from:

$34.99

CS456 Assignment 1 Solution

1 Assignment ObjecOve
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 SpecificaOons
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 communicaOon process. In the negoOaOon stage, the client and the server negoOate on a random port (<r_port>) for later use through a fixed negoOaOon port (<n_port>) of the server. Later in the transacOon 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 connecOon with the server using <server_address> as the server address and <n_port> as the negoOaOon 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 reversed). To iniOate this negoOaOon, the client sends a request code (<req_code>), an integer (e.g., 13), a]er creaOng the TCP connecOon. If the client fails to send the intended <req_code>, the server closes the TCP connecOon and conOnues 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 connecOon 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 receives 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 conOnue listening on its <n_port> for subsequent client requests. For simplicity, we assume, there will be only one client in the system at a Ome. So, the server does not need to handle simultaneous client connecOons.
2.3 Client Program (client)
You should implement a client program, named client. It will take four command line inputs:
<server_address>, <n_port>, <req_code>, and <msg> in the given order.
2.4 Server Program (server)
You should also implement a server program, named server. The server will take <req_code> as a command line parameter. The server must print out the <n_port> value in the following format as the first line in the stdout:
SERVER_PORT=<n_port>
For example, if the negoOaOon port of the server is 52500, then the server should print: SERVER_PORT=52500
2.5 Example ExecuOon
Two shell scripts named server.sh and client.sh are provided. Modify them according to your choice of programming language. You should execute these shell scripts which will then call your client and server programs.
• Run server: ./server.sh <req_code>
• Run client: ./client.sh <server address> <n_port> <req_code> 'A man, a plan, a canal— Panama!'
3 Hints
Below are some points to remember while coding/debugging to avoid trivial problems.
• 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 connecOons, 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 negoOaOon.
• If both the server and the client are running in the same system, 127.0.0.1 or localhost can be used as the desOnaOon 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.2 Hand in InstrucOons
Submit all your files in a single compressed file (.zip, .tar etc.) using LEARN in dedicated Dropbox. The filename should include your username and/or student ID. You must hand in the following files / documents:
• Source code files.
• Makefile: your code must compile and link cleanly by typing “make” or “gmake” (when applicable).
• README file: this file must contain instrucOons on how to run your program, which undergrad machines your program was built and tested on, and what version of make and compilers you are using.
• Modified server.sh and client.sh scripts.
Your implementaOon will be tested on the machines available in the undergrad environment linux.student.cs which includes the following hosts:

4.3 DocumentaOon
4.4 EvaluaOon
Work on this assignment is to be completed individually.
5 AddiOonal Notes:
• You have to ensure that both <n_port> and <r_port> are available. Just selecOng a random 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 addiOonal (manual) input is required to run any of the server or client.

More products