尝试运行服务器时出现Python Socket Program错误

时间:2017-10-20 01:17:51

标签: python sockets networking network-programming

我一直试图调试这个错误,我已经有一段时间没有成功。它是一个使用python的基本套接字程序,它从客户端接收一个小写句子,服务器以大写形式返回它。客户端文件工作得很好,但是当我在控制台中运行“python server.py”时,我一直收到此错误,返回此消息:

[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

这是我的代码:

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()

0 个答案:

没有答案