pythonanywhere - How do I use websockets to transmit messages as per the web2py messaging example?

拜拜、爱过 提交于 2019-12-24 04:58:29

问题


So I've built out an app to test websockets with web2py and pythonanywhere and I got it to work locally but when uploading to pythonanywhere it doesn't work. I think the reason is that I'm sending things to localhost (127.0.0.1) but have no idea where I need to send things (and listen to) when uploading.

the debug.py script is:

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

the listen.html

{{extend 'layout.html'}}

<div id="test_div">
    {{=d}}
</div>

{{=script}}

the send.html

{{extend 'layout.html'}}

{{=form}}

A few more points:

  • I start the tornado server as per this from a bash terminal in pythonanywhere.

    python websocket_messaging.py -p 8880 -k mykey
    
  • I've got a free account on pythonanywhere and would like to test this out before I start paying for one.

  • I found this which seems to imply I can't do what I want on pythonanywhere?


回答1:


PythonAnywhere dev here -- unfortunately WebSockets don't work on our service at the moment :-(



来源:https://stackoverflow.com/questions/32094042/pythonanywhere-how-do-i-use-websockets-to-transmit-messages-as-per-the-web2py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!