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?
PythonAnywhere dev here -- unfortunately WebSockets don't work on our service at the moment :-(