-
-
Save kausality/79d9169752593a459234dfd37368b25a to your computer and use it in GitHub Desktop.
Simple iostream example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| import socket | |
| import tornado.ioloop | |
| import tornado.iostream | |
| import tornado.options | |
| # Nothing listening here | |
| host = "127.0.0.1" | |
| port = 12345 | |
| def connect(): | |
| sock = socket.socket() | |
| stream = tornado.iostream.IOStream(sock) | |
| stream.set_close_callback(on_closed) | |
| stream.connect((host, port), on_connect) | |
| def on_connect(): | |
| logging.info("on_connect") | |
| def on_closed(): | |
| logging.info("on_closed") | |
| def main(): | |
| tornado.options.parse_command_line() | |
| tornado.ioloop.IOLoop.instance().add_callback(connect) | |
| tornado.ioloop.IOLoop.instance().start() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment