I have completed my web socket API in Python:
#import socket module
from socket import *
serverPort = 80 #Port Used
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(('', serverPort))
serverSocket.listen(1)
print "The server is ready to receive"
while True:
#Establish the connection
print 'Ready to serve...'
connectionSocket, addr = serverSocket.accept()
try:
message = connectionSocket.recv(1024)
filename = message.split()[1]
f = open(filename[1:])
outputdata = f.read()
print outputdata
connectionSocket.send('\nHTTP OK\n')
connectionSocket.send(outputdata)
for i in range(0, len(outputdata)):
connectionSocket.send(outputdata[i])
connectionSocket.close()
except IOError:
connectionSocket.send('\n404 Not Found\n')
connectionSocket.send('\n404 Not Found\n')
And I have a simple .html
file which is on my XAMPP server. The task is to run the Python API and then access the host (in my case localhost:80
) in order to access the .html
file and get from the console all the necessary information.
Here is the problem: After I try to run my API it gives me the following error:
Traceback (most recent call last):
File "hw2.py", line 6, in <module>
serverSocket.bind(('', serverPort))
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use