Created
October 5, 2011 18:13
-
-
Save dlo/1265208 to your computer and use it in GitHub Desktop.
Socket.IO server-side implementations
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
| class Application(object): | |
| greenlet = None | |
| def __call__(self, environ, start_response): | |
| path = environ['PATH_INFO'].strip('/') | |
| if path.startswith("socket.io"): | |
| socketio = environ['socketio'] | |
| while True: | |
| message = socketio.recv() | |
| if len(message) == 1: | |
| message = message[0] | |
| data = msgpack.loads(message.decode("base-64")) | |
| if data['action'] == 'register': | |
| self.id = data['id'] | |
| greenlet = Greenlet.spawn(updater, self) | |
| self.greenlet = greenlet | |
| else: | |
| if not socketio.connected(): | |
| self.greenlet.kill() | |
| return [] | |
| else: | |
| return not_found(start_response) |
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
| class StatConnection(tornadio.SocketConnection): | |
| greenlet = None | |
| def on_message(self, message): | |
| data = msgpack.loads(message.decode("base-64")) | |
| if data['action'] == 'register': | |
| self.id = data['id'] | |
| greenlet = Greenlet.spawn(updater, self) | |
| self.greenlet = greenlet | |
| def on_close(self): | |
| self.greenlet.kill() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment