here is explained how to do, that is not possible in regular web2py """ This file is part of the web2py Web Framework Copyrighted by Massimo Di Pierro <[email protected]> License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
Attention: Requires Chrome or Safari. For IE of Firefox you need https://github.com/gimite/web-socket-js 1) install tornado easy_install tornado 2) start this app: python gluon/contrib/comet_messaging.py -k mykey -p 8888 3) from any web2py app you can post messages with from gluon.contrib.comet_messaging import comet_send comet_send('http://127.0.0.1:8888','Hello World','mykey','mygroup') 4) from any template you can receive them with <script> $(document).ready(function(){ if(!web2py_comet('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> When the server posts a message, all clients connected to the page will popup an alert message Or if you want to send json messages and store evaluated json in a var called data: <script> $(document).ready(function(){ var data; web2py_comet('ws://127.0.0.1:8888/realtime/mygroup ',function(e){data=eval('('+e.data+')')}); }); </script> - All communications between web2py and comet_messaging will be digitally signed with hmac. - All validation is handled on the web2py side and there is no need to modify comet_messaging.py - Multiple web2py instances can talk with one or more comet_messaging servers. - "ws://127.0.0.1:8888/realtime/" must be contain the IP of the comet_messaging server. - Via group='mygroup' name you can support multiple groups of clients (think of many chat-rooms) Here is a complete sample web2py action: def index(): form=LOAD('default','ajax_form',ajax=True) script=SCRIPT(''' jQuery(document).ready(function(){ var callback=function(e){alert(e.data)}; if(!web2py_comet('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.comet_messaging import comet_send comet_send('http://127.0.0.1:8888 ',form.vars.message,'mykey','mygroup') return form Acknowledgements: Tornado code inspired by http://thomas.pelletier.im/2010/08/websocket-tornado-redis/ """ On Wed, Feb 23, 2011 at 2:53 PM, Anthony <[email protected]> wrote: > On Wednesday, February 23, 2011 5:49:24 AM UTC-5, elffikk wrote: > >> you need a flash or javascript widget and a "comet" web2py controller that >> will push data to the browser >> when a step is done you will send a message to the browser wich will >> redraw to show the progress >> > > Also, it looks like you code is simply using the print statement to report > progress. Although that will show up in the terminal window (as you have > observed), that won't send any output to the web page (i.e., it won't affect > the HTTP response). To send output to a web page, your controller function > must return a dict to a view or return a string. See > http://web2py.com/book/default/chapter/03#Say-Hello. >

