0% found this document useful (0 votes)
3 views3 pages

Lab3 New

The document outlines a laboratory exercise focused on socket programming in Python, divided into two parts: creating a simple client that communicates with a server using TCP and UDP, and developing a proxy to relay messages to the server. Students are provided with templates and resources for coding, and must submit their work in a zip file containing their code and a README.md document. The exercises include specific requirements for functionality, message handling, and documentation to ensure clarity and prevent plagiarism.
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)
3 views3 pages

Lab3 New

The document outlines a laboratory exercise focused on socket programming in Python, divided into two parts: creating a simple client that communicates with a server using TCP and UDP, and developing a proxy to relay messages to the server. Students are provided with templates and resources for coding, and must submit their work in a zip file containing their code and a README.md document. The exercises include specific requirements for functionality, message handling, and documentation to ensure clarity and prevent plagiarism.
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/ 3

Laboratory Exercise 3 – Socket programming

Overview
In the third lab exercise we have a socket programming task in Python which you
can use as a basis for the course work. The exercise is split in to two parts. First part
is a simple client that talk with the server using TCP and UDP. For this part you are
given a commented template that you can use to complete the task. This part can
be used as a template for the coursework. In the second part you are expected to
create a proxy which relays your message to the server.

How to access the server


The server you are expected to interact with can be found from 195.148.20.105 TCP
and UDP port 20000.

Writing the code


You can use the code templates found in Moodle as the basis for you work.
You can write your code using your favourite code editor. If you are new to python
or just need a refresher check the following links
https://www.tutorialspoint.com/python/python_networking.htm
https://www.pythoncentral.io/encoding-and-decoding-strings-in-python-3-x/
https://www.tutorialspoint.com/python3/python_strings.htm

Returning your code


Return your code to Moodle in a zip file that contains the following files:

⦁ Exercise 1 and 2 codes as separate python files

⦁ Comment your code

⦁ README.md document that contains the following information:

⦁ Names and student IDs of all your group members

⦁ Whether or not you completed both exercises

⦁ Potential bugs or other issues that your program has

⦁ Short explanation on how to start your program

⦁ For example: ‘to start my program type python3 lab3.py

1
195.148.20.105 20000 “hello there” ‘

⦁ If you get help from some other group, please make it clear in the comments
or in README. Codes will be checked for plagiarism

Exercise 1
First exercise is to write a simple client, that communicates with the server using
TCP and UDP. Check the code template for more in detail description on what you
need to implement. Program should work in the following way:
1. Reads an address, port and a message from command line arguments

⦁ Basically, your program should start when the following is typed to the
terminal:

⦁ python3 lab3.py 195.148.20.105 20000 “hello there”


2. Connects to the given server address and port using TCP socket
3. Sends the given message using the TCP socket

⦁ The message is ”hello there”


4. Reads and prints the reply from the TCP socket
Implement the required code in the send_and_receive_tcp function found in the
template. Test that the TCP portion works before you move to the UDP part.
After you TCP portion works implement the UDP part to the send_and_receive_udp
function. Instructions below
1. Sends the message received from the TCP connection back to the server over UDP

⦁ Servers UDP port is 20000


2. Reads and prints the replies sent by the server over UDP in a loop until a message
saying “QUIT”
Exercise 2
In the second part of this exercise you are expected to create a proxy that forwards
the messages your program from exercise one produces to the server. Your proxy
also needs to print what it receives and from where. There is a template in Moodle
that you can use to create your proxy
Requirements:

⦁ Proxy needs to be a separate python program that you execute in the same
machine as your client.

⦁ Proxy needs to forward TCP and UDP traffic using sockets

⦁ Socket should be binded to port 21000 or something close to it.

2
⦁ Proxy needs to print all the messages it forwards and clearly indicate who
sent the message.

⦁ Proxy needs to stay on until it is manually shutdown, either via keypress or


CTRL+C, and be able to continuously forward messages.

⦁ Basically, it should not shut down after it has forwarded the TCP and
UDP transactions once but continue to do so until it is shut down

You might also like