所以我在弄乱一些我发现的python chat room code,我将其配置为没有问题,除非客户端向服务器发送消息时,服务器不会将消息发送给每个服务器。客户端,因为广播代码中的BrokenPipeError
。我在堆栈溢出时浏览了其他一些问题,但似乎无法找出错误的确切原因以及解决方法。
这是客户端发送消息时服务器终端上显示的内容:
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "WMserver.py", line 24, in handle_client
broadcast(bytes(msg, "utf8"))
File "WMserver.py", line 43, in broadcast
sock.send(bytes(prefix, "utf8")+msg)
BrokenPipeError: [Errno 32] Broken pipe
所引用的代码是这样的:
def broadcast(msg, prefix=""): # prefix is for name identification.
"""Broadcasts a message to all the clients."""
for sock in clients:
sock.send(bytes(prefix, "utf8")+msg)
sock.send()
中似乎存在某种问题,但我不知道这可能是什么。