그래서 web2py와 pythonanywhere로 웹 소켓을 테스트하는 앱을 만들었고 로컬에서 작동하도록했지만 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 dev-불행히도 WebSocket은 현재 우리 서비스에서 작동하지 않습니다 :-(
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다