have problem in python socket programming

Joined
Oct 5, 2009
Messages
1
Reaction score
0
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top