Socket Programming Assignment

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Concordia University

COEN-366: Communication Networks and Protocols


Instructor: Prof. Chadi Assi

As we have seen in the lab, we were able to create a client and a server, then we can
establish a connection between them. This assignment will be in the same way;
however, you are asked to write a server only (webserver) and the client will be the
browser.
You have to write a http_server.py file that contains the following:
1. Create a TCP connection that listens on port number 12000
2. Read the incoming HTTP request and parse it to get the name of the
file the browser is asking for.
3. Create an HTTP response that contains the data of the file.
Send this HTTP response to the client (browser)

At a high level, your web server will be structured something like the
following:

Listen for connections


Forever loop:
Accept new connection from incoming client
Parse HTTP/1.0 request
Ensure well-formed request (return error otherwise)
Determine if target file exists and if permissions are set properly (return error
otherwise)
Transmit contents of file to connect (by performing reads on the file and writes
on the socket)
Close the connection
Some instructions:
1. Create an html file called (coen366.html), the content of this file is provided at
the end of the assignment (see below).
2. You must put the .html file in the same directory of your http_server.py file.
3. After creating the server, you have to run it.
4. Go to your browser and then type the URL that connects to the server you
have created. The URL is as the following:
http://IP_ADDRESS_OF_YOUR_SERVER:PORT_NUMBER_YOUR_
SERVER_LISTEN_TO/coen366
5. Hit ENTER, you must see now the content of the file.
6. Submit the http_server.py file to moodle only.
Gd Luck!
// CONTENT OF the html file.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Welcome to COEN 366</h1>
<p>Course info:</p>
<ul>
<li>Given by Prof. Chadi Assi</li>
<li>Prof's email: [email protected]</li>
<hr>
<li>There are three TAs for this course:<br/>
<ul>
<li>Shreya Khisa</li>
<li>Ali Amhaz</li>
<li>Y A Joarder</li>
</ul>
</li>
<hr>
</ul>
</body>
</html>

You might also like