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
- Host: GitHub
- URL: https://github.com/codler/python-websocket
- Owner: codler
- Created: 2010-12-05T10:45:26.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2010-12-31T10:44:57.000Z (about 15 years ago)
- Last Synced: 2025-03-11T07:17:35.036Z (11 months ago)
- Language: Python
- Homepage:
- Size: 98.6 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
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!