因此,我构建了一个应用程序来使用 web2py 和 pythonanywhere 测试 websockets,并且它可以在本地工作,但是当上传到 pythonanywhere 时它不起作用。我认为原因是我正在将内容发送到本地主机(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}}
发送.html
{{extend 'layout.html'}}
{{=form}}
还有几点:
-
我按照以下方式启动龙卷风服务器this https://github.com/web2py/web2py/blob/master/gluon/contrib/websocket_messaging.py从 pythonanywhere 中的 bash 终端。
python websocket_messaging.py -p 8880 -k mykey
我在 pythonanywhere 上有一个免费帐户,想在开始付费之前测试一下。
I found this https://www.pythonanywhere.com/wiki/Using%20Tornado这似乎意味着我无法在 pythonanywhere 上做我想做的事情?
PythonAnywhere 开发人员在这里 - 不幸的是,WebSockets 目前无法在我们的服务上运行:-(
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)