I was just about saying that I was taking a hack at websocket_messaging.py 
before even trying to go through Richard's code only to realize Stifan just 
mentioned that. Anyway, what happens now is, when I start the 
websocket_messaging.py with

python web2py/gluon/contrib/websocket_messaging.py -k mykey -p 8888

things seem to work just fine, except the onclose function in

<script>
    $(document).ready(function(){
        var data;
        $.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/home/',
             function(e){data=eval('('+e.data+')')},  #onmessage
             function(){ajax('someone_online',[],'');}, #onopen
             function(){ajax('{{='someone_offline/%s' % 
auth.user.id}}',[],'');}); #the onclose function that doesn't work
    });
</script>

1436875501.27:CONNECT to home
1436875502.29:MESSAGE to home:$('#userStatus').append('<div>saso just came 
online</div>').fadeIn('slow').slideDown('slow')
1436875502.29:MESSAGE to 
home:$('#usersOnline').html($('<span>1</span>').fadeIn('slow').slideDown('slow'))




When I start the websocket_messaging.py with

python web2py/gluon/contrib/websocket_messaging.py -k mykey -p 8888 -t 
9b09360f-9052-4e5a-bb1e-a1fad72b3498

the onclose function seems to execute, but it executes immediately after 
open executes and then sends the messages, hence the socket is closed even 
before the messages can reach the client.

1436882466.78:CONNECT to home
1436882466.78:DISCONNECT from home
1436882467.12:MESSAGE to home:$('#userStatus').prepend('<div>saso just came 
online</div>').fadeIn('slow').slideDown('slow')
1436882467.13:MESSAGE to 
home:$('#usersOnline').html($('<span>2</span>').fadeIn('slow').slideDown('slow'))
1436882467.74:MESSAGE to home:$('#userStatus').append('<div>saso just went 
offline</div>').fadeIn('slow').slideDown('slow')
1436882467.74:MESSAGE to 
home:$('#usersOnline').html($('<span>1</span>').fadeIn('slow').slideDown('slow'))


then i realized something that I didn't exactly understand.

if running with -t post a token to allow a client to join using the token
the message here is the token (any uuid)
allows only authorized parties to joins, for example, a chat


it explains why the immediate disconnection after a connection is 
established because of some 'authorization'. how do i allow "authorized 
parties to join"? the users are already logged in :/

On Saturday, July 11, 2015 at 12:53:34 AM UTC, 黄祥 wrote:
>
> please take a look at web2py/gluon/contrib/websocket_messaging.py
> after that please try it, if still not success, please show the traceback 
> error or your code, so that people in this group can help.
>
> best regards,
> stifan
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to