python - How to make a Socket.IO client connect to a Python3 Websocket server -
i'm attempting socket.io client connect python websocket server created using aaugustin's websockets library , asyncio. using example on page created following web socket server:
import asyncio import websockets datetime import datetime @asyncio.coroutine def producer(): return str(datetime.now()) @asyncio.coroutine def handler(websocket, path): while true: message = yield producer() if not websocket.open: break yield websocket.send(message) yield asyncio.sleep(3) start_server = websockets.serve(handler, "localhost", 8765) asyncio.get_event_loop().run_until_complete(start_server) asyncio.get_event_loop().run_forever()
the view served using flask , looks following:
<!doctype html> <head> <title>websocket client test</title> </head> <body> <script src="https://cdn.socket.io/socket.io-1.3.5.js"></script> <script> console.log(io); var socket = io("ws://localhost:8765/"); console.log(socket); </script> </body>
whenever socket.io tries connect, throws following error:
xmlhttprequest cannot load http://localhost:8765/socket.io/?eio=3&transport=polling&t=1434254272412-0. no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:5001' therefore not allowed access. response had http status code 400.
the access-control-allow-origin seems imply i'm trying make request location different hostname, i'm not doing. don't know why throwing error. created python client script connects server fine, i'm little lost i'm missing.
the access-control-allow-origin seems imply i'm trying make request location different hostname, i'm not doing.
different port considered different origin lots of implementations. https://developer.mozilla.org/en-us/docs/web/security/same-origin_policy:
two pages have same origin if protocol, port (if 1 specified), , host same both pages
Comments
Post a Comment