on_open Publish Possible?

25 views
Skip to first unread message

Paul Bailey

unread,
Nov 2, 2013, 1:21:54 PM11/2/13
to python...@googlegroups.com
I'm using the Django chat example to play around with Pulsar and I have to say it is really awesome.

One thing I was trying to do was publish a message like 'John entered the room' on_open.  However, when I publish in on_open, it doesn't get published until the the first message comes in from the user.  I see you used the on_open in the client to send a blank message to kind of kick things in.

Sending the blank message definitely works but seems like a hack.  Is this a bug or something that will change in the future?

Great job on the library!

Luca Sbardella

unread,
Nov 3, 2013, 10:43:12 AM11/3/13
to Paul Bailey, python...@googlegroups.com
On 2 November 2013 18:21, Paul Bailey <paul.m...@gmail.com> wrote:
I'm using the Django chat example to play around with Pulsar and I have to say it is really awesome.

Thanks
 
One thing I was trying to do was publish a message like 'John entered the room' on_open.  However, when I publish in on_open, it doesn't get published until the the first message comes in from the user.  I see you used the on_open in the client to send a blank message to kind of kick things in.
 
Correct, it tells the server a new user has landed on the chat room. If you don't do that, the ``on_open`` method on the server will get invoked the first time the user post a message.

 
Sending the blank message definitely works but seems like a hack.  Is this a bug or something that will change in the future?


Sending and empty message allows the ``on_open`` method to get called before a user sends a message.

This is the way the WS handler/protocol is designed at the moment, it is not a bug

1) Client send request
2) Server send the handshake headers (upgrade)
3) the ``on_open`` method in the websocket handler is called when the first message from the client is received.

I'm not sure if (3) is the right implementation and therefore the ``on_open`` method could be called just after the handshake-headers are sent. In which case the initial empty message is not required.
I'm open to suggestions/use cases.

Great job on the library!

 
Thanks again

Paul Bailey

unread,
Nov 5, 2013, 8:11:35 AM11/5/13
to python...@googlegroups.com, Paul Bailey
Yeah from my experience with other web socket libraries the on_open should be called right after the upgrade automatically.

Also, talked about your library at the Houston Python Web Meetup last night as part of my Web Socket talk.  A lot of folks liked it.

lsbardel

unread,
Nov 6, 2013, 10:32:29 AM11/6/13
to python...@googlegroups.com, Paul Bailey
On Tuesday, November 5, 2013 1:11:35 PM UTC, Paul Bailey wrote:
Yeah from my experience with other web socket libraries the on_open should be called right after the upgrade automatically.

This will be done in 0.8, with several other fixes.
 
Also, talked about your library at the Houston Python Web Meetup last night as part of my Web Socket talk.  A lot of folks liked it.

 
Cool, can you post the link?

Paul Bailey

unread,
Nov 6, 2013, 11:35:47 AM11/6/13
to python...@googlegroups.com, Paul Bailey
Here is the meetup site: http://www.meetup.com/python-web-houston/

And the presentation I gave: bit.ly/PythonWebSockets

Reply all
Reply to author
Forward
0 new messages