Trying my hand at python web sockets for the first time and stuck on this bug:
AttributeError: type object '_socketobject' has no attribute 'gethostbyname'
from socket import *
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind((socket.gethostname(), 80))
serverSocket.listen(5)
while True:
print 'Ready to serve.'
connectionSocket, addr = serverSocket.accept()
print 'connection is from', addr
try:
message = connectionSocket.recv(2048)
filename = message.split()[1]
print filename
f = open(filename[1:])
outputdata = f.read()
connectionSocket.send('HTTP/1.1 200 OK\r\n\r\n')
for i in range(0, len(outputdata)):
connectionSocket.send(outputdata[i])
connectionSocket.close()
except IOError:
print 'IOError'
connectionSocket.send('HelloWorld.html')
connectionSocket.close()
serverSocket.close()
Also, if you have any recommendations for libraries to use to make this easier/more like something you'd actually write, I'd much appreciate the input.