【发布时间】:2015-11-12 16:00:22
【问题描述】:
所以我已经构建了一个应用程序来使用 web2py 和 pythonanywhere 测试 websockets,我让它在本地工作,但是当上传到 pythonanywhere 时它不起作用。我认为原因是我正在向 localhost (127.0.0.1) 发送内容,但不知道上传时需要在哪里发送内容(并收听)。
debug.py 脚本是:
def listen():
script=SCRIPT('''
jQuery(document).ready(function(){
var callback=function(e){$("#test_div").html(e.data)};
if(!web2py_websocket('ws://127.0.0.1:8880/realtime/mygroup',callback))
alert("html5 websocket not supported by your browser, try Google Chrome");
});
''')
d = ''
return { 'd':d , 'script':script }
def send():
form=LOAD('debug','ajax_form',ajax=True)
return { 'form':form }
def ajax_form():
form=SQLFORM.factory(Field('message'))
if form.accepts(request,session):
import websocket_messaging
reload( websocket_messaging )
websocket_messaging.websocket_send( 'http://127.0.0.1:8880' , form.vars.message , 'mykey' , 'mygroup' )
return form
listen.html
{{extend 'layout.html'}}
<div id="test_div">
{{=d}}
</div>
{{=script}}
send.html
{{extend 'layout.html'}}
{{=form}}
还有几点:
【问题讨论】:
标签: websocket web2py pythonanywhere