Skip to content

Instantly share code, notes, and snippets.

@Zaharid
Last active August 29, 2015 14:06
Show Gist options
  • Save Zaharid/7d9288cdd162ba684166 to your computer and use it in GitHub Desktop.
Save Zaharid/7d9288cdd162ba684166 to your computer and use it in GitHub Desktop.
Minimun websocket client for tornado
from tornado.websocket import websocket_connect
from tornado import ioloop
from tornado import gen
@gen.coroutine
def onconnect(future):
ws = future.result()
while 1:
m = input("message?\n")
ws.write_message(m)
msg = yield ws.read_message()
print(msg)
if __name__ == '__main__':
future = websocket_connect('ws://localhost:8888/ws',callback = onconnect)
ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment