【问题标题】:pythonanywhere - How do I use websockets to transmit messages as per the web2py messaging example?pythonanywhere - 如何根据 web2py 消息传递示例使用 websockets 传输消息?
【发布时间】: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}}

还有几点:

  • 我从 pythonanywhere 中的 bash 终端按照this 启动龙卷风服务器。

    python websocket_messaging.py -p 8880 -k mykey
    
  • 我在 pythonanywhere 上有一个免费帐户,并想在开始付费之前对其进行测试。

  • 我找到了this,这似乎暗示我无法在 pythonanywhere 上做我想做的事?

【问题讨论】:

    标签: websocket web2py pythonanywhere


    【解决方案1】:

    这里是 PythonAnywhere 开发者——不幸的是,WebSockets 目前无法在我们的服务上运行 :-(

    【讨论】:

    • 我担心这可能是答案。近期有计划开展这项工作吗?
    • 它肯定在待办事项清单上,但我们没有预计到达时间。我已经为我们的任务跟踪器 FWIW 添加了赞成票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    • 2016-10-25
    相关资源
    最近更新 更多