0

id like to write a handler for the standalone server coming with pywebsocket (http://code.google.com/p/pywebsocket) that uses a thread. in the example coming with pywebsocket the handler is just a file with a function:

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

ive tried to add a thread:

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

but the server crashes without any comment... so how is this done?

thanks for any pointers.

Elisa
  • 1
  • 1

1 Answers1

0

The standalone server isn't designed to receive messages non-blocking. From the documentation of the class "MessageReceiver" in msgutil.py (at least not when using SSL):

This class receives messages from the client.

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.
Joakim
  • 11,468
  • 9
  • 44
  • 50