I tried to setup a simple websocket to try and learn the concept so I can
use it in my app. I took the instructions in websocket_messaging.py and
built the following minimal app. I am on debian squeeze using chromium and
tornado 4.2.. I started websocket_messaging.py as per the instructions: *python
gluon/contrib/websocket_messaging.py -k mykey -p 8888*. When I enter some
test into the index controller form I see it in the terminal that I
started websocket_messaging.py in ....but I do not see a flash alert in the
websocket_receiver view....Am I missing something in the concept? is it a
browser problem?..any help would be greatly appreciated
*Controller:*
*default.py*
def index():
form=LOAD('default', 'ajax_form', ajax=True)
script=SCRIPT('''
jQuery(document).ready(function(){
var callback=function(e){alert(e.data)};
if(!$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup',
callback))
alert("html5 websocket not supported by your browser, try
Google Chrome");
});
''')
return dict(form=form, script=script)
def ajax_form():
form=SQLFORM.factory(Field('message'))
if form.accepts(request,session):
from gluon.contrib.websocket_messaging import websocket_send
websocket_send(
'http://127.0.0.1:8888', form.vars.message, 'mykey',
'mygroup')
return form
def websocket_receiver():
return dict()
*Views:*
*index.html*
{{extend 'layout.html'}}
WEBSOCKET TEST:
{{=form}}
{{=script}}
*websocket_receiver.html*
{{extend 'layout.html'}}
<h1>This is the receiver.html template</h1>
<script>
$(document).ready(function(){
if(!$.web2py.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>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.