我有一个下面给出的 python 服务器脚本
# create the server, binding to localhost on port 9999
#
server = SocketServer.TCPServer((options.ip, options.port), cmdHandler)
While running a Python server script I am getting the following error:
File "C:\Devcon\OCDServer_New.py", line 225, in runTest
server = SocketServer.TCPServer((options.ip, options.port), cmdHandler)
File "C:\Python27\lib\SocketServer.py", line 419, in __init__
self.server_bind()
File "C:\Python27\lib\SocketServer.py", line 430, in server_bind
self.socket.bind(self.server_address)
File "C:\Python27\lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
**socket.error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted**
如何解决这个问题?在一个链接中,我发现套接字关闭是一种解决方案。但这里的问题是在创建套接字本身时出现的。可能是因为它之前已打开且未正确关闭。但我无法重置整个事情并再次运行脚本。被困在这里了。
最佳答案
尝试使用不同的端口,看看是否收到相同的消息或不同的消息。其他东西可能正在使用相同的端口,因此您的代码无法使用它。
关于python - python 服务器代码中的套接字错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28235256/