Warning: You can use only the packages that were used in the lecture notes.

In this lab, we will write simple programs using sockets.

[10pts] Part 1: Netcat chats

Finish Activity 1 in Class on sockets. In particular, bring up two terminals. Have a necat chat between the two terminals. Try a TCP connection, and then a UDP connection. In this case,

Deliverables:

Two screeenshots in your lab report: one for a TCP chat, and the other for a UDP chat. Throught the semester, if you add screenshots, please add them in the lab report (along with explanations).

[25pts] Part 2: UDP netcat server

Finish Activity in Class on sockets. In particular, create a UDP netcat program (server part) called serv_udp.py. Your program should work with the following command:
nc -u ip_addr 9000
Refer to the socket manual page. A sample run:
~$ python3 serv_udp.py
From ('127.0.0.1', 34001) : b'hello\n'
How are you?
quit
~$ nc -u 127.0.0.1 9000
hello
How are you?
^C
Note Deliverables:

[25pts] Part 3: HTTP Client

Write a TCP client program httpc.py that will successfully communicate with (i.e. send data to and receive data from) a remote server on port 80 (http).
Note
Sample runs:
~$ python3 httpc.py info.cern.ch
HTTP/1.1 200 OK
Date: Mon, 07 Jun 2021 21:40:35 GMT
Server: Apache
Last-Modified: Wed, 05 Feb 2014 16:00:31 GMT
ETag: "286-4f1aadb3105c0"
Accept-Ranges: bytes
Content-Length: 646
Connection: close
Content-Type: text/html

<html><head></head><body><header>
<title>http://info.cern.ch</title>
</header>

<h1>http://info.cern.ch - home of the first website</h1>
<p>From here you can:</p>
<ul>
<li><a href="http://info.cern.ch/hypertext/WWW/TheProject.html">Browse the first website</a></li>
<li><a href="http://line-mode.cern.ch/www/hypertext/WWW/TheProject.html">Browse the first website using the line-mode browser simulator</a></li>
<li><a href="http://home.web.cern.ch/topics/birth-web">Learn about the birth of the web</a></li>
<li><a href="http://home.web.cern.ch/about">Learn about CERN, the physics laboratory where the web was born</a></li>
</ul>
</body></html>
~$ python3 httpc.py http-textarea.badssl.com
HTTP/1.1 200 OK
Server: nginx/1.10.3 (Ubuntu)
Date: Fri, 20 Jan 2023 16:21:46 GMT
Content-Type: text/html
Content-Length: 713
Last-Modified: Thu, 27 Oct 2022 19:09:20 GMT
Connection: keep-alive
ETag: "635ad760-2c9"
Cache-Control: no-store
Accept-Ranges: bytes

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="shortcut icon" href="/icons/favicon-red.ico"/>
  <link rel="apple-touch-icon" href="/icons/icon-red.png"/>
  <title>textarea.badssl.com</title>
  <link rel="stylesheet" href="/style.css">
  <style>body { background: red; }</style>
</head>
<body>
<style>
#content textarea {
  font-size: 4vw;
}
</style>

<div id="content">
  <h1 style="font-size: 5vw;">
    textarea.<br>badssl.com
  </h1>
  <br><br><br>
  <textarea placeholder="Type here." autofocus></textarea>
</div>

<div id="footer">
  This page contains a <code><textarea></code> input.
</div>

</body>
</html>

Deliverables:

[30pts] Part 4: HTTP Server

Write a simple HTTP server program https.py. It should listen at port 8000, and supports two following web pages: When https.py is running on the localhost, the Chrome web browser should show something like the following:
index.html


hobby.html
xxx.html

Tips

Deliverables

[10pts] Lab Report and Submission

Write a lab report by using the provided template. The writing quality of the lab report matters.
~/bin/submit -c=IT430 -p=lab02 *.py *.html lab02.docx