
Concept explainers
Lab 2: Web Server Lab
In this lab, you will learn the basics of socket
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 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.
Code
Below you will find 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.
Running the Server
Put an HTML file (e.g., helloworld.html) in the same directory that the server is in. Run the server program. Determine the IP address of the host that is running the server (e.g., 127.0.0.1). Open a browser and provide the corresponding URL. For example:
http://127.0.0.1:13331/helloworld.html
‘helloworld.html’ is the name of the file you placed in the server directory. Note also the use of the port number after the colon. GradeScope will test your code using port 13331. In the above example, we have used the port number 13331. The browser should then display the contents of helloworld.html. If you omit ":13331", 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. Next, try to get a file that is not present at the server. You should get a “404 Not Found” message.
What to Hand in
Submit the code to GradeScope (include helloworld.html if it exists) using your GitHub repository. Program file name must be solution.py.
Notes:
- There are clients (browsers) that will not present HTML content unless encoded HTTP headers are submitted with the message from the web server.
- HTTP status codes “200 OK” and “404 Not Found” are required to be part of the Web Server in order to receive full credit on this assignment.
Skeleton Code
Code is available below and on Google Drive:
https://drive.google.com/file/d/1_9O4p68nlK6a5XC5haOZ5OVTinuF_7cu/view?usp=sharing
Skeleton Python Code for the Web Server
#import socket module
from socket import *
import sys # In order to terminate the program
def webServer(port=13331):
serverSocket = socket(AF_INET, SOCK_STREAM)
#Prepare a server socket
#Fill in start
#Fill in end
while True:
#Establish the connection
print('Ready to serve...')
connectionSocket, addr = #Fill in start #Fill in end
try:
message = #Fill in start #Fill in end
filename = message.split()[1]
f = open(filename[1:])
outputdata = #Fill in start #Fill in end
#Send one HTTP header line into socket
#Fill in start
#Fill in end
#Send the content of the requested file to the client
for i in range(0, len(outputdata)):
connectionSocket.send(outputdata[i].encode())
connectionSocket.send("\r\n".encode())
connectionSocket.close()
except IOError:
#Send response message for file not found (404)
#Fill in start
#Fill in end
#Close client socket
#Fill in start
#Fill in end
serverSocket.close()
sys.exit() # Terminate the program after sending the corresponding data
if __name__ == "__main__":
webServer(13331)

Actually, python is a easiest programming language.
It is a dynamically typed programming language.
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- Write a program in C that requires one command-line argument that is an IPv4 dotted-decimal address. Create an IPv4 TCP socket and bind this address to the socket along with some port, say 9999. Call listen and then pause. Write a similar program that takes an IPv6 hex string as the command-line argument and creates a listening IPv6 TCP socket. Start the IPv4 program, specifying the wildcard address as the argument. Then, go to another window and start the IPv6 program, specifying the IPv6 wildcard address as the argument. Can you start the IPv6 program since the IPv4 program has already bound that port? Doesthe SO_REUSEADDR socket option make a difference? What if you start the IPv6 program first, and then try to start the IPv4 program?arrow_forward7. Complete the following sentence: Templating is an example of ... O A POST request Separation of Concerns (SOC) A GET request HTTP request methods Incorrect Templating is unrelated to the HTTP methodarrow_forwardsuppose you are working with two disparate systems, and one system depends on data from the other but the data formatting is different, so you need to specify a software application that pulls data from one system, changes the format to suit the second system and sends that data. This type of application is most commonly called: The Central Number Cruncher (CNC) Extract, Transform, Load middleware (ETL) A Transmission Control Protocol (TCP) A Data Transformer Engine (DTE)arrow_forward
- For Programming Assignment #1 you will be writing your own port scanner. You can use any programming language you choose. The TAs and I have used Python. Your requirements are: 1. Your program must take an input of a target host. It must accept both an IP address or domain name. 2. Your program must take an input of a range of ports. 3. Your program must have a connection timeout so that it will stop trying to connect to a target that is not responding. 4. Your program must print the scan start time. 5. Your code must be commented. Please submit a copy of your code and a screenshot of it working as a PDF file. Then submit your source code (.py, .java, etc.) as a second file. Your screenshot should be similar to the one provided below and it should show at least one open and one closed port. Happy coding! student@kali:-/Desktop$ python portscan.py Enter a target to scan: 10.1.123.158 Please enter the range of ports you would like to scan on the target Enter a start port: 20 Enter a end…arrow_forwardUsing traceroute write me a script that does the following, asks for your first name and last name, and asks you for an URL to a site on the Internet. perform a tracerroute to that address, then I want the program to indicate Hello <your name> The system <ip address> is alive (or) not alive. Attach the screenshots to your paper with three sentences about the screenshot. and post them to the thread.arrow_forwardWrite a code in C that prints the following: Prints default TCP send and receive buffer sizes.Prints default UDP send and receive buffer sizes.Prints default SCTP send and receive buffer sizes.arrow_forward
- In C/C++ network programming; create a simple web proxy that handles the connection between a client and server. I currently have been working on a client and server echoing each other from the geeks for geeks example but can't find much information in CODING up a web based proxy. I do understand the type of proxy to create but do not understand how to code one up in terms of client-proxy-server connection through https. The answer that I am looking for is how to create the web proxy in C. You can use the geeks for geeks example (client/server) or use one of your own.arrow_forwardHello. I need help developing a C or C++ program that simulate an 8-port Ethernet switch. The switch initially has no knowledge about the hosts connected to each port. It learns frame addresses and stores-and-forwards the frames. The input text file "in.txt" contains information of the incoming frames, one frame per line. There are 4 pieces of data per line: frame ID, arrival port, frame source address,and frame destination address. The frames arrive at the switch in the order of which they appearin the input file. Destination address "X" indicates a broadcast frame. Thank you! ********************PLEASE YOUR CODE MUST BE COMPLETE, COMPILE AND EXECUTE**************** The output text file "out.txt" has 8 lines. Each line lists all the frames departing from each port, here is an example: "in.txt" contains 5 incoming frames:F1 P2 B--AF2 P6 D--CF3 P5 E--BF4 P7 F--DF5 P6 D--X"out.txt" should list the departing frames on each port:P1: F1 F2 F5P2: F2 F3 F5P3: F1 F2 F5P4: F1 F2 F5P5: F1…arrow_forwardTHREAD -"C LANGUAGE" ONLY Write a program that uses 5 threads. Initialize a shared variable with a value of 0. Each thread must add its Thread ID (tid) to the shared variable. Once a thread has done the addition, print the ID of the thread. It is important to make use of mutexes so that only one thread is incrementing the shared variable at a time. Output the value of the shared variable once all threads have finished incrementing it.arrow_forward
- Dynamic linking has one huge advantage and a number of smaller ones. Name the huge one and a couple of the little onesarrow_forwardSockets are low-level networking interfaces between computers. Many programming languages come standard with socket libraries for creating socket connections. In this lab, we’ll study the usage of networking sockets in Python to write a custom client/server program. Client/Server source code as a ZIP or RAR file in D2L Word document outlining the description of your program. The word document should contain screenshots containing your name on the VM and reports of what’s occurring in them. Demonstrate your socket solution accomplishes the following: The client connects to the server Client and server successfully exchange messages Following the TCP stream in Wireshark Identifying the message sent in Wireshark Any additional functionality you created in your solution. please use python.arrow_forward2. LAMP stands for "Linux, Apache, MySQL, and PHP," and it is a web hosting stack that fits well together. The letters denote and.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





