coding utf8 and improve comment
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
|
# -*- coding: utf8 -*-
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This file is part of the web2py Web Framework
|
This file is part of the web2py Web Framework
|
||||||
Copyrighted by Massimo Di Pierro <mdip...@cs.depaul.edu>
|
Copyrighted by Massimo Di Pierro <mdip...@cs.depaul.edu>
|
||||||
@@ -17,13 +19,13 @@ Attention: Requires Chrome or Safari. For IE of Firefox you need https://github.
|
|||||||
3) from any web2py app you can post messages with
|
3) from any web2py app you can post messages with
|
||||||
|
|
||||||
from gluon.contrib.websocket_messaging import websocket_send
|
from gluon.contrib.websocket_messaging import websocket_send
|
||||||
websocket_send('http://127.0.0.1:8888','Hello World','mykey','mygroup')
|
websocket_send('http://127.0.0.1:8888', 'Hello World', 'mykey', 'mygroup')
|
||||||
|
|
||||||
4) from any template you can receive them with
|
4) from any template you can receive them with
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
if(!$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup',function(e){alert(e.data)}))
|
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");
|
alert("html5 websocket not supported by your browser, try Google Chrome");
|
||||||
});
|
});
|
||||||
@@ -35,7 +37,7 @@ Or if you want to send json messages and store evaluated json in a var called da
|
|||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
var data;
|
var data;
|
||||||
$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup',function(e){data=eval('('+e.data+')')});
|
$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup', function(e){data=eval('('+e.data+')')});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -49,11 +51,11 @@ Or if you want to send json messages and store evaluated json in a var called da
|
|||||||
Here is a complete sample web2py action:
|
Here is a complete sample web2py action:
|
||||||
|
|
||||||
def index():
|
def index():
|
||||||
form=LOAD('default','ajax_form',ajax=True)
|
form=LOAD('default', 'ajax_form', ajax=True)
|
||||||
script=SCRIPT('''
|
script=SCRIPT('''
|
||||||
jQuery(document).ready(function(){
|
jQuery(document).ready(function(){
|
||||||
var callback=function(e){alert(e.data)};
|
var callback=function(e){alert(e.data)};
|
||||||
if(!$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup',callback))
|
if(!$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup', callback))
|
||||||
|
|
||||||
alert("html5 websocket not supported by your browser, try Google Chrome");
|
alert("html5 websocket not supported by your browser, try Google Chrome");
|
||||||
});
|
});
|
||||||
@@ -65,7 +67,7 @@ Here is a complete sample web2py action:
|
|||||||
if form.accepts(request,session):
|
if form.accepts(request,session):
|
||||||
from gluon.contrib.websocket_messaging import websocket_send
|
from gluon.contrib.websocket_messaging import websocket_send
|
||||||
websocket_send(
|
websocket_send(
|
||||||
'http://127.0.0.1:8888',form.vars.message,'mykey','mygroup')
|
'http://127.0.0.1:8888', form.vars.message, 'mykey', 'mygroup')
|
||||||
return form
|
return form
|
||||||
|
|
||||||
Acknowledgements:
|
Acknowledgements:
|
||||||
|
|||||||
Reference in New Issue
Block a user