Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

LAB 2: Socket Programming using Python, Study notes of Computer Networks

LAB 2: Socket Programming using Python. Instructions: ... Run the Client and the Server processes on different computers and check if they work.

Typology: Study notes

2021/2022

Uploaded on 09/27/2022

margoth
margoth 🇬🇧

4.4

(11)

229 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
IIT Goa CS 212 Computer Networks
Instructor: Dr. Neha Karanjkar
LAB 2: Socket Programming using Python
Instructions:
This lab can be done individually or in teams of max 2 persons. Any sharing of
solutions/code between separate teams will be treated as plagiarism.
Only one person in the team needs to make the submission on Google Classroom on
behalf of the team.
Each Team is required to submit:
a brief report in pdf format (filename: Lab2_<NAME as on classroom>.pdf)
all code put together in a single Python file
(filename Lab2_<NAME>.py)
You must write the names of all team members in your report and code files.
You will be asked a viva based on the work you submit, and will need to show a demo of
your working code.
PART 1: UDP SOCKETS [5 points]
1. Study the template provided for using UDP sockets in Python (files UDP_Server.py and
UDP_Client.py). Make sure that you understand the purpose of UDP sockets, and the
steps for creating and using these sockets. Run the Client and Server processes and
observe the output.
2. Run the Client and the Server processes on different computers and check if they work
as expected (you will need to specify the server’s IP address).
1
pf3
pf4
pf5

Partial preview of the text

Download LAB 2: Socket Programming using Python and more Study notes Computer Networks in PDF only on Docsity!

IIT Goa CS 212 Computer Networks Instructor: Dr. Neha Karanjkar

LAB 2: Socket Programming using Python

Instructions:

  • This lab can be done individually or in teams of max 2 persons. Any sharing of solutions/code between separate teams will be treated as plagiarism.
  • Only one person in the team needs to make the submission on Google Classroom on behalf of the team.
  • Each Team is required to submit: ◦ a brief report in pdf format (filename: Lab2_.pdf) ◦ all code put together in a single Python file (filename Lab2_.py) ◦ You must write the names of all team members in your report and code files.
  • You will be asked a viva based on the work you submit, and will need to show a demo of your working code. PART 1: UDP SOCKETS [5 points]
  1. Study the template provided for using UDP sockets in Python (files UDP_Server.py and UDP_Client.py). Make sure that you understand the purpose of UDP sockets, and the steps for creating and using these sockets. Run the Client and Server processes and observe the output.
  2. Run the Client and the Server processes on different computers and check if they work as expected (you will need to specify the server’s IP address).

To get a different computer with a visible IP address, you could either use a laptop/mobile phone in the same network OR use Amazon Web Service AWS EC2 (a free account will get you a linux machine with a public IP address). If you do not have access to another computer with a reachable IP address, you can skip this question.

  1. Design and implement a Client-Server system that uses UDP sockets to do the following: ◦ The client sends the server a request. The request string can either be: “SEND_DATE” or “SEND_TIME”. ◦ The server runs in a infinite loop where it keeps waiting for requests. Whenever it sees a request, it responds by sending either the current DATE or the current TIME in (HH:MM:SS) format as specified in the request. ◦ When the Client receives a response, it prints it. ◦ The Client runs in a loop where it generates multiple such requests, and the time between successive requests varies randomly between 1-2 seconds. HINT: You can use the following line of code to generate a random amount of delay, uniformly distributed between 1-2 seconds: PART 2: TCP SOCKETS [5 points]
  2. Study the template provided for using TCP sockets in Python (files TCP_Server.py and TCP_Client.py). Make sure that you understand the purpose of TCP sockets and the steps for creating and using these sockets. Observe the differences between UDP and TCP sockets and the steps for their use. Run the TCP Client and Server processes and observe the output.
  3. Start up Wireshark and apply a filter such that only the traffic generated by your Client and Server processes is displayed. Identify the messages used by TCP during the Handshake and the actual text sent by the two processes. Are the “contents” of the packet (the message strings) visible within Wireshark? (This is what we’d expect since the strings aren’t encrypted before sending.) import time, random ... time.sleep(random.uniform(1,2))
  1. For systems such as those described in question 6, think of how you could modify the Server so that it can handle multiple clients at the same time. For each connection (using TCP sockets), the Server should provide the same service as described. There are several ways to implement this. One way is to use mutiple threads for the Server, one per connection. A skeleton for a multi-threaded server program can be found in this answer on StackOverflow: https://stackoverflow.com/a/40351010/ In this question, we wish to design such a multi-Client system to implement a “Chat Room” as follows: ◦ The Client process acts like a chat window. It takes user input, sends appropriate requests to the Server, and displays the messages sent by the server to the human user. ◦ The Server process acts like a chat room manager. It allows client processes to login to the chat room (each client needs to have a unique name). The server keeps track of all the clients that are currently logged in. Whenever any interesting event happens, (such as new user logging in or leaving the chat room) the status is broadcast to all connected clients. Also, whatever each user types is broadcast to all clients. ◦ At the beginning, the user is requested for a “login name”. The client process then sends a login request to the chat room (Server) with this name. ◦ After logging in, whatever lines the user types is broadcast to all clients along with the sender’s name. The following lines show an example of output that might be displayed to two different clients. Client 1 is the first to join the chat room.

Client 1 Enter login name:

Batman Server: time=10.01 Batman has joined. Member count= Server: time=11.01 Voldemort has joined. Member count= Anyone here? Voldemort: Crucio! Aaaaaaahrrhhhhhh.. quit Client 2 Enter login name: Voldemort Server: time=11.01 Voldemort has joined. Member count= Batman: Anyone here? Crucio! Batman: Aaaaaaahrrhhhhhh.. Server: time=13.01 Batman has left. Member count=