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

Assignment 2

it

Uploaded by

itxsiddique1
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)
5 views4 pages

Assignment 2

it

Uploaded by

itxsiddique1
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

BS Computer Science — Computer Networks | Assignment 2: Transport Layer & Socket Programming

ASSIGNMENT 2
Socket Programming, Transport Layer Services,
Multiplexing & De-Multiplexing

Course Semester Group Size Total Marks


Computer Networks 2nd — BS Program 2 Students 25

AI Policy & Academic Integrity


You are encouraged to use AI tools (ChatGPT, Claude, Gemini) as a learning aid. However:
1. Every AI-assisted answer must be followed by your own explanation in
different words.
2. Parts marked with [AI-Proof] will be evaluated in a 5-minute verbal quiz during
submission — you must explain your code and answers orally.
3. Logs of your actual AI conversations (screenshots or exports) must be
submitted as an appendix.
4. Submitting AI-generated work verbatim without understanding will result in
zero marks for that part.

Objective
Build a working client-server communication system in Python and demonstrate how the transport
layer manages multiple concurrent clients through sockets, ports, and multiplexing. You will
combine practical implementation with conceptual understanding — including honest use of AI
assistance as a documented part of your process.

Marks Overview
Part Description Marks AI-
Proof?
Part A TCP Client-Server Implementation 8 Partial
Part B Multi-client & Multiplexing Demo 5 Yes
Part C Conceptual Report (your own words) 6 Yes
Part D AI Usage Log & Reflection 4 Yes
Bonus UDP Implementation +3 No

Part A: TCP Client-Server Implementation (8 Marks)


BS Computer Science — Computer Networks | Assignment 2: Transport Layer & Socket Programming

Implement a basic TCP client-server system in Python. AI tools may help you understand syntax
and structure, but you must be able to explain every line during the verbal quiz.

A1. Server Requirements (tcp_server.py)


• Create a TCP socket and bind to a port of your choice (e.g., 12000)
• Listen for and accept at least 2 simultaneous client connections
• Use threading to handle each client in a separate thread
• For each received message, print:
◦ Client IP address and port number
◦ The message content
◦ The thread/process ID handling that client
• Echo the message back to the client with a timestamp
• Gracefully handle client disconnection

A2. Client Requirements (tcp_client.py)


• Create a TCP socket and connect to the server
• Send at least 3 messages in a loop
• Print the server's reply for each message
• Send "exit" to cleanly close the connection

Guided AI Task — Part A


Ask ChatGPT or Claude: "Explain what [Link]() returns and why it creates a new
socket instead of reusing the existing one." Then write the explanation in your own words in
the report. This earns 1 of your 8 marks and will be verified in the verbal quiz.

Part B: Multiplexing & De-Multiplexing Demonstration (5 Marks) [AI-


Proof]
This part tests whether you understand what is happening in your own code — not just that you
wrote it.

B1. Required Output Format


Your server must print the following for each client connection:
[ Thread-1 ] New connection from [Link]:54321
[ Thread-1 ] Received: Hello from Client A
[ Thread-2 ] New connection from [Link]:54322
[ Thread-2 ] Received: Hello from Client B

B2. Analysis Questions (answer in report)


Answer these in your report. AI may help you draft answers, but rephrase in your own words and
be ready to answer verbally:
• Both clients connect to the same server port. How does the server tell them apart? What
specific data identifies each client uniquely?
BS Computer Science — Computer Networks | Assignment 2: Transport Layer & Socket Programming

• If a third client from the same IP but a different source port connects, does the server treat it
as the same client? Why or why not?
• Draw a diagram showing: two clients, the network, the server port, and two separate
sockets. Label the 4-tuple for each connection.

Part C: Conceptual Report (6 Marks) [AI-Proof]


Write a 2-3 page report. You may use AI to get first drafts or explanations, but every section must
be rewritten in your own words. Sections submitted verbatim from AI will receive zero marks.

Required Sections
C1. TCP vs UDP — When Would You Choose Each? (1.5 marks)
Do not just list differences. Describe a realistic scenario for each protocol and justify your choice.
For example: "For a live multiplayer game, I would use UDP because..."
C2. The Transport Layer's Role (1.5 marks)
Explain in your own words: what problem does the transport layer solve that the network layer
does not? Use your own analogy (not one copied from a textbook or AI).
C3. Multiplexing vs De-Multiplexing (2 marks)
Using your actual server output from Part B as evidence, explain multiplexing and de-multiplexing.
Your explanation must reference specific IP addresses and port numbers from your own
screenshot.

Part D: AI Usage Log & Reflection (4 Marks) [AI-Proof]


This is a required part, not optional. AI usage is expected — hiding it is considered academic
dishonesty.

D1. Conversation Log


Submit screenshots or exported text of your AI conversations as an appendix. Include at least 3
distinct prompts you used.

D2. Reflection (write in report)


Answer the following honestly:
• What did you ask AI for, and what did it get right or wrong?
• Where did AI help you understand something better?
• Where did you have to go beyond what AI gave you? (e.g., a bug AI could not solve, or an
explanation that did not match your actual output)
• What is one thing you now understand that you did not before this assignment?
Tip: How to get the most from AI tools
• Ask AI to explain a concept three different ways until one clicks.
BS Computer Science — Computer Networks | Assignment 2: Transport Layer & Socket Programming

• When code does not work, paste the error into AI and ask it to explain — but then fix
it yourself.
• Ask AI: "What question should I be asking about this topic that I haven’t asked yet?"
• Never trust AI output about port numbers or socket behavior without testing it
yourself.

Bonus: UDP Implementation (+3 Marks)


Implement a UDP echo server and client. Key difference to demonstrate: the server does NOT call
accept() — explain in your report why, and what this tells you about connectionless
communication.
• udp_server.py — binds to port, receives datagram, sends reply
• udp_client.py — sends message, prints reply
• In report: explain why two different clients sending to the same UDP port both reach the
same socket (relate back to your answer in Part B)

Deliverables
File / Item Description Required?
tcp_server.py Threaded TCP server with full output format Yes
tcp_client.py TCP client sending multiple messages Yes
[Link] 2–3 page report (Parts B, C, D) Yes
ai_log appendix Screenshots/exports of AI conversations Yes
udp_server.py UDP server (bonus) Optional
udp_client.py UDP client (bonus) Optional

Verbal Quiz — What to Expect


During submission, the instructor will pick one student from each group and ask 2–3
questions such as:
• "Point to the line in your code where de-multiplexing happens."
• "What does conn, addr = [Link]() return? Explain each variable."
• "If I run three clients at the same time, what would your server print?"
• "Why doesn’t your UDP server call accept()?"
If you cannot answer, marks will be deducted from the AI-Proof sections regardless of code
quality.

You might also like