KEMBAR78
EE502 W3 Programming | PDF | Port (Computer Networking) | Networking
0% found this document useful (0 votes)
20 views5 pages

EE502 W3 Programming

The document outlines a programming assignment for EE502 focused on creating a basic web server using socket programming in Python. Students will learn to handle HTTP requests, send responses, and manage file retrieval, including error handling for missing files. A report summarizing the lab experience, challenges faced, and potential improvements is also required to be submitted along with screenshots of the working program.

Uploaded by

shwetasah2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views5 pages

EE502 W3 Programming

The document outlines a programming assignment for EE502 focused on creating a basic web server using socket programming in Python. Students will learn to handle HTTP requests, send responses, and manage file retrieval, including error handling for missing files. A report summarizing the lab experience, challenges faced, and potential improvements is also required to be submitted along with screenshots of the working program.

Uploaded by

shwetasah2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

EE502—Computer Communication Networks

Programming Assignment (Week 3)

Web Server
Objectives
In this lab, you will learn the basics of socket programming for TCP connections in Python:
how to create a socket, bind it to a specific address and port, as well as send and receive a
HTTP packet. You will also learn some basics of HTTP header format. You will develop a web
server that handles one HTTP request at a time. Your web server should accept and parse
the HTTP request, get the requested file from the server’s file system, create an HTTP
response message consisting of the requested file preceded by header lines, and then send
the response directly to the client. If the requested file is not present in the server, the
server should send an HTTP “404 Not Found” message back to the client.

Equipment List
Two PCs or laptops installed with Python 2.7.9 connected to the Internet

Procedure
1. Create a Python program on the server PC. Figure 3 is the skeleton code for the web
server. You are to complete the skeleton code. The places where you need to fill in
code are marked with #Fill in start and #Fill in end. Each place may require one or
more lines of code. You may follow the sample working program as shown in Figure 4.

2. Create an HTML file (e.g., congratulation.html) as shown in Figure 1 and save in the
same directory that the server program is in. You can create the file using MS Word
and save as type: web page, as shown in Figure 2.

Figure 1

1
Figure 2

3. Before you run the server program, determine the IP address of the host that is
running the server (e.g., 128.238.251.26).

You can get the IP address by executing the script in the Python shell, as shown
below.

>>>import socket
>>>print socket.gethostbyname(socket.gethostname())

4. From another host, open a browser and provide the corresponding URL. For example:
http://128.238.251.26:6787/congratulation.html

‘congratulation.html’ is the name of the file you placed in the server directory. Note
also the use of the port number after the colon. You need to replace this port number
with whatever port you have used in the server code. In the above example, we have
used the port number 6787. The browser should then display the contents of
congratulation.html. If you omit ":6787", the browser will assume port 80 and you will
get the web page from the server only if your server is listening at port 80.

5. Then, try to get a file that is not present at the server. You should get a “404 Not
Found” message.

6. You will hand in the complete server code along with the screenshots of your client
browser, verifying that you actually receive the contents of the HTML file from the
server.

#import socket module


from socket import *
serverSocket = socket(AF_INET, SOCK_STREAM)
2
#Prepare a sever socket

#Fill in start
#Fill in end
Figure 3

# Import socket module


from socket import *

# Create a TCP server socket


#(AF_INET is used for IPv4 protocols)
#(SOCK_STREAM is used for TCP) 3
serverSocket = socket(AF_INET, SOCK_STREAM)

# Assign a port number


serverPort = 6787
Figure 4

Programming Assignment Report—Due at the end of Week 3

4
Write a basic report commenting on the above API programming experiment. The report must
include a cover page with the lab title, the course number, your student name, and your DeVry
DSI number. You must also include a basic introduction that addresses the purpose of this
programming lab. Students must also include basic background information on how the
experiment was set up. Summarize key findings. What were some of the challenges, if any, that
you faced in completing this assignment? How did you overcome those challenges? What
possible improvement can you make in this assignment?

Attach a screenshot of your running program on web server and client browser.

You might also like