I have been trying to debug this error I've been getting for a while to no success. It is a basic socket program using python that takes in a lower case sentence from the client and the server returns it in uppercase form. The client file works perfectly fine, however I keep getting this error when trying to run "python server.py" in the console, returning this message:
[yanb@athena:45]> python server.py
Traceback (most recent call last):
File "server.py", line 7, in <module>
serverSocket.bind(('',serverPort))
File "< string >", line 1, in bind
socket.error: [Errno 98] Address already in use
Here is my code:
client.py
from socket import *
serverName = '127.0.0.1'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
sentence = raw_input('Input lowercase sentence:')
clientSocket.send(sentence)
modifiedSentence = clientSocket.recv(1024)
print 'From Server:', modifiedSentence
clientSocket.close()
server.py
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind(('',serverPort))
serverSocket.listen(1)
print 'The server is ready to receive'
while 1:
connectionSocket, addr = serverSocket.accept()
sentence = connectionSocket.recv(1024)
capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence)
connectionSocket.close()