An open API service indexing awesome lists of open source software.

https://github.com/codler/python-websocket

Python websocket - asynchronous socket - draft-ietf-hybi-thewebsocketprotocol-00
https://github.com/codler/python-websocket

Last synced: 7 months ago
JSON representation

Python websocket - asynchronous socket - draft-ietf-hybi-thewebsocketprotocol-00

Awesome Lists containing this project

README

          

# Python WebSocket

* Tested and works on Python 2.5

* PROTOCOL - draft-hixie-thewebsocketprotocol-76 / draft-ietf-hybi-thewebsocketprotocol-00

* CONNECTION METHOD - Asynchronous socket (RECOMMEND) / "One-thread-per-connection" (no longer maintained)

## How to use

class WebSocketHandler(BaseWebSocketHandler):
def onconnect(self):
pass

def onrecieve(self, message):
for connection in self.connections:
self.onsend(connection, message)

def onsend(self, connection, message):
if isinstance(message, unicode):
message = message.encode('utf-8')
elif not isinstance(message, str):
message = str(message)
connection.send("\x00%s\xff" % message)

def ondisconnect(self):
pass

#### Some notes
* One-thread-per-connection takes about >8MB RAM for each connection! I recommend using asynchronous-socket instead.

* Bug, "self.server.connections" does not always remove unused connection from the list.

## Feedback

I appreciate all feedback, thanks!