pythonanywhere - 如何根据web2py消息传递示例使用websockets传输消息?

时间:2015-08-19 11:19:47

标签: websocket web2py pythonanywhere

所以我已经构建了一个用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}}

还有几点:

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

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

  • 我发现this似乎意味着我无法在pythonanywhere上做我想做的事情?

1 个答案:

答案 0 :(得分:1)

PythonAnywhere dev在这里 - 遗憾的是,WebSockets目前无法在我们的服务上运行: - (

相关问题