1

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()
0TTT0
  • 1,288
  • 1
  • 13
  • 23
Ben Yan
  • 61
  • 1
  • 9
  • 1
    Possible duplicate of [socket.error: \[Errno 48\] Address already in use](https://stackoverflow.com/questions/19071512/socket-error-errno-48-address-already-in-use) – 0TTT0 Oct 20 '17 at 01:26
  • Okay solved the error, though its still confusing to me. All I did was change the port number to 13000 for both client and server files and the server ran fine. – Ben Yan Oct 20 '17 at 02:02
  • There is most likely already a process on your computer running that is using port 12000.. – 0TTT0 Oct 20 '17 at 02:07

0 Answers0