when running the server, for example:
my ip address : port / HelloWorld.html
The browser should display the content of HelloWorld.html .
Then try to get a file that is not present at the server. You should get a 404 not found message.
#import socket module
from socket import *
serverSocket = socket(AF_INET, SOCK_STREAM)
#Prepare a sever socket
#Fill in start
#Fill in end
while 1:
#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
clientfile = connectionSocket.makefile('rw',0)
#Generate the response message for file found
#Fill in start
#Fill in end
#Send the content of the requested file to the client
for i in range(0, len(outputdata)):
clientfile.write(outputdata)
clientfile.close()
connectionSocket.close()
except IOError:
clientfile = connectionSocket.makefile('rw',0)
#Generate the response message for file not found
#Fill in start
#Fill in end
clientfile.close()
#Close client socket
#Fill in start
#Fill in end
serverSocket.close()
i may work out some of it, but its hard for me for the highlight place.
pls, someone help me!
my ip address : port / HelloWorld.html
The browser should display the content of HelloWorld.html .
Then try to get a file that is not present at the server. You should get a 404 not found message.
#import socket module
from socket import *
serverSocket = socket(AF_INET, SOCK_STREAM)
#Prepare a sever socket
#Fill in start
#Fill in end
while 1:
#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
clientfile = connectionSocket.makefile('rw',0)
#Generate the response message for file found
#Fill in start
#Fill in end
#Send the content of the requested file to the client
for i in range(0, len(outputdata)):
clientfile.write(outputdata)
clientfile.close()
connectionSocket.close()
except IOError:
clientfile = connectionSocket.makefile('rw',0)
#Generate the response message for file not found
#Fill in start
#Fill in end
clientfile.close()
#Close client socket
#Fill in start
#Fill in end
serverSocket.close()
i may work out some of it, but its hard for me for the highlight place.
pls, someone help me!