id喜欢为使用线程的pywebsocket(http://code.google.com/p/pywebsocket)附带的独立服务器编写处理程序。 在pywebsocket附带的示例中,处理程序只是一个带有函数的文件:
def web_socket_transfer_data(request):
while True:
line = request.ws_stream.receive_message()
if line is None:
return
request.ws_stream.send_message(line)
if line == _GOODBYE_MESSAGE:
return
我试图添加一个帖子:
class _Stub(threading.Thread):
def __init__ (self):
threading.Thread.__init__(self)
self._test = 0
def run(self):
while True:
time.sleep(5)
self._test = self._test + 1
但是服务器崩溃而没有任何评论...... 那怎么办呢?
感谢任何指示。
答案 0 :(得分:0)
独立服务器不能用于接收非阻塞消息。来自msgutil.py中“MessageReceiver”类的文档(至少在使用SSL时不是这样):
此课程从客户端接收消息。
This class provides three ways to receive messages: blocking, non-blocking, and via callback. Callback has the highest precedence. Note: This class should not be used with the standalone server for wss because pyOpenSSL used by the server raises a fatal error if the socket is accessed from multiple threads.