5

when I run my code on my pc and try to connect socket with my index.html on localhost no problem but when I try to run my code on server and try to connect socket with index.html(it locate on my pc) I get :

Router <tornadio2.session.ConnectionInfo object at 0x7f7bfc5fac10>
INFO:tornado.access:200 GET /socket.io/1/
DEBUG:root:Initializing websocket handler.
WARNING:tornado.access:403 GET /socket.io/1/websocket/c0532cea9001408c50a9c854f4bce5d8

and after that it switch protocal to xhr-polling but I want to use websocket.

INFO:tornado.access:200 GET /socket.io/1/xhr-polling/62f9b31662c984201685a830c764765e
DEBUG:root:Initializing xhr-polling transport.
DEBUG:root:>>> 1::/socket
DEBUG:root:<<< 1::/socket
DEBUG:root:<<< 3::/socket:connected!

what can I do to fix that problem ?

3

2 Answers 2

21

The html must be loaded from the same server as the websocket unless you override check_origin to allow cross-origin access: http://www.tornadoweb.org/en/stable/websocket.html#tornado.websocket.WebSocketHandler.check_origin

0
-6

Solved it. for tornadio2 users you have to do that :

add this code to persistent.py(it locate in tornadio2)

def check_origin(self, origin):
    return True
2
  • 5
    It will be polite to accept right answer provided above
    – Michael M.
    Oct 20, 2014 at 21:28
  • This answer correct in your use case but it could be very unsecure without an explanation. Please accept the right answer.
    – MrBlaise
    Dec 5, 2019 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.