Using non-blocking websockets in mod_pywebsocket

95 views
Skip to first unread message

Novan

unread,
Jun 30, 2011, 3:20:49 AM6/30/11
to pywebsocket
Hi,

I've searched for non-blocking websocket using the mod_pywebsocket.
During searcg I found this link
http://code.google.com/p/pywebsocket/source/browse/trunk/src/mod_pywebsocket/msgutil.py
to the project repository where a non-blocking method in MessageSender
and MessageReceiver is included.

I'm very new to python and this is my first script I write in this
language. How is it possible to use this two classes in the
mod_pywebsocket especially in the two methods web_socket_transfer_data
and web_socket_do_extra_handshake?

Thanks for help.
Novan

Takeshi Yoshino

unread,
Jul 4, 2011, 4:40:29 AM7/4/11
to pyweb...@googlegroups.com
Hi,

Please take the request object inside web_socket_transfer_data and instantiate MessageSender or MessageReceiver with it as you want.

They spawn a new thread for running send_message/receive_message. You can do
- non-blocking receive by calling receiver.receive_nowait (where receiver is instantiated by onmessage=None)
- asynchronous receive by instantiating receiver by onmessage=<some method for handling received message>
- asynchronous send by sender.send_nowait.

Please make sure that you don't exit the web_socket_transfer_data function while you're serving some request since when you return from that function, pywebsocket closes the connection.

Takeshi
Reply all
Reply to author
Forward
0 new messages