0% found this document useful (0 votes)
29 views4 pages

CS456 Assignment 1

The assignment focuses on TCP and UDP socket programming in a client-server setup, where the client sends string reversal requests to the server. It involves a two-stage communication process: negotiation using TCP to obtain a random port for data transfer, followed by string reversal using UDP. Students must implement both client and server programs, adhering to specific input requirements and submission guidelines by the due date of October 22, 2021.

Uploaded by

s53cao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

CS456 Assignment 1

The assignment focuses on TCP and UDP socket programming in a client-server setup, where the client sends string reversal requests to the server. It involves a two-stage communication process: negotiation using TCP to obtain a random port for data transfer, followed by string reversal using UDP. Students must implement both client and server programs, adhering to specific input requirements and submission guidelines by the due date of October 22, 2021.

Uploaded by

s53cao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Can I print useful state information to stdout?

2. Can we change python to python3?


3. Do we need to handle edge cases such as checking server IP address and port?
Do we need to try catch or maybe just let the program die?
Assignment 1
Computer Networks (CS 456/656)
Fall 2021
Introductory Socket Programming
Due Date: Friday, October 22, 2021, before midnight (11:59 PM)
Work on this assignment is to be completed individually

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.

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 negoPaPon port of the server is 52500, then the server should print:
SERVER_PORT=52500

2.5 Example ExecuPon


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 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.2 Hand in InstrucPons


Submit all your files in a single compressed file (.zip, .tar etc.) using LEARN in dedicated Drop-
box. 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 ap-
plicable).
• README file: this file must contain instrucPons on how to run your program, which under-
grad machines your program was built and tested on, and what version of make and com-
pilers you are using.
• Modified server.sh and client.sh scripts.
Your implementaPon will be tested on the machines available in the undergrad environment
linux.student.cs which includes the following hosts:
4.3 DocumentaPon
Since there is no external documentaPon required for this assignment, you are expected to
have a reasonable amount of internal code documentaPon (to help the markers read your
code).
You will lose marks if your code is unreadable, sloppy, or not efficient.

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.

You might also like