CS 4392 - Lab 1 - Web Server PDF

Title CS 4392 - Lab 1 - Web Server
Course Computer Networks
Institution Texas Tech University
Pages 2
File Size 51.5 KB
File Type PDF
Total Downloads 42
Total Views 131

Summary

CS 4392 - Lab 1 - Web Server...


Description

Lab 1: Web Server Lab

CS 4392-002

Abiraam Nagarajan

Skeleton Python Code for the Web Server #import socket module from socket import * import sys # In order to terminate the program

serverSocket = socket(AF_INET, SOCK_STREAM) #Prepare a sever socket serverPort=9789 serverSocket.bind((‘’, serverPort)) serverSocket.listen(1) while True: #Establish the connection print('Ready to serve...') connectionSocket, addr = serverSocket.accept() try: message = connectionSocket.recv(1024).decode() print(connectionSocket.recv(1024), connectionSocket.split()[0], ‘Ready to receive()[1])’ filename = message.split()[1] f = open(filename[1:]) outputData = f.read() Print outputData connectionSocket.send(outputData) #Send one HTTP header line into socket

Lab 1: Web Server Lab

CS 4392-002

Abiraam Nagarajan

Connection socket.send(capitalizedSentence.encode())

#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 connectionSocket.send (‘\nHTTP/1.1 404 Not found\n\n’) #Close client socket connectionSocket.close() serverSocket.close() sys.exit() #Terminate the program after sending the corresponding data...


Similar Free PDFs