import socket
import sys
resp = 'HTTP/1.1 200 OK\n' \
'Date: Mon, 27 Jul 2009 12:28:53 GMT\n' \
'Server: Apache/2.2.14 (Win32)\n' \
'Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT\n' \
'Content-Length: 88\n' \
'Content-Type: text/html\n' \
'Connection: Closed\n' \
'<html> <body> <h1>Hello, World!</h1> </body> </html>'
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port
server_address = ('localhost', 80)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)
# Listen for incoming connections
sock.listen(1)
while True:
# Wait for a connection
print >>sys.stderr, 'waiting for a connection'
connection, client_address = sock.accept()
try:
# Receive the data in small chunks and retransmit it
while True:
data = connection.recv(4096)
if data:
print('sending: %s') % resp
connection.sendall(resp)
else:
break
finally:
# Clean up the connection
connection.close()
DLaczego gdy po odpaleniu tego programu firefox laczac sie na localhost nie wyswietla hello world ? Co jest nie tak z resp ??