pythonanywhere-根据web2py消息传递示例,如何使用websockets传输消息?
因此,我开发了一个应用程序,用web2py和Pythonywhere测试WebSocket,我让它在本地工作,但当上传到Pythonywhere时,它不工作。我认为原因是我正在将内容发送到localhost(127.0.0.1),但不知道上传时需要将内容发送(并收听)到哪里 debug.py脚本是:pythonanywhere-根据web2py消息传递示例,如何使用websockets传输消息?,websocket,web2py,pythonanywhere,Websocket,Web2py,Pythonanywhere,因此,我开发了一个应用程序,用web2py和Pythonywhere测试WebSocket,我让它在本地工作,但当上传到Pythonywhere时,它不工作。我认为原因是我正在将内容发送到localhost(127.0.0.1),但不知道上传时需要将内容发送(并收听)到哪里 debug.py脚本是: def listen(): script=SCRIPT(''' jQuery(document).ready(function(){ var cal
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}}
还有几点:
- 我从Pythonywhere的bash终端启动tornado服务器
python websocket_messaging.py -p 8880 -k mykey
- 我在Pythonywhere上有一个免费帐户,我想在开始付费之前测试一下
- 我发现这似乎意味着我不能在蟒蛇上做我想做的事。在哪里
python websocket_messaging.py -p 8880 -k mykey