the basic idea of websocket is that input data must be validated by web2py 
therefore data can only be received from web2py.


In your JS code you simply do:

<script>                                                                   
                                                         
   $(document).ready(function(){                                           
                                                            
      
if(!web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup',function(e){alert(e.data)}))
 
                                        
         alert("html5 websocket not supported by your browser, try Google 
Chrome");                                                    
   });                                                                     
                                                            
 </script> 

This makes the client join the group "mygroup" and is data is received, the 
callback function is called.
You post by doing an ajax to web2py and web2py does

from gluon.contrib.websocket_messaging import websocket_send               
                                                         
websocket_send('http://127.0.0.1:8888','Hello World','mykey','mygroup')

This sends the message "hello world" to all the members of the group 
"mygroup".

Notice that web2py and websocket share a "mykey". This is how security is 
implemented. web2py validates input and it knows the key for posting. the 
only way to allow posting directly from JS would be to remove this security 
step or creating some authentication at the JS level. I do not trust 
authentication at the JS level.





On Friday, 26 July 2013 09:08:37 UTC-5, Eduardo Cruz wrote:
>
> Is there a way to send data to a websocket from javascript 
> using web2py_websocket ?

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to