Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/egebilecen/pywebsocket
A simple RFC6455 Websocket server implementation in Python.
https://github.com/egebilecen/pywebsocket
python-websocket websocket-server
Last synced: about 1 month ago
JSON representation
A simple RFC6455 Websocket server implementation in Python.
- Host: GitHub
- URL: https://github.com/egebilecen/pywebsocket
- Owner: egebilecen
- License: gpl-3.0
- Created: 2017-10-05T17:48:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-09-28T01:22:20.000Z (over 3 years ago)
- Last Synced: 2024-11-09T07:47:58.394Z (2 months ago)
- Topics: python-websocket, websocket-server
- Language: Python
- Homepage:
- Size: 736 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pywebsocket
Simple websocket server library written in Python.Example Server Code:
**main.py**```python
from pywebsocket.server import WebsocketServer, WebsocketClientdef on_client_connect(server : WebsocketServer,
client : WebsocketClient) -> None:
# Add this client's socket id to a channel's user list.
server.default_channel["users"].append(client.get_id())
client.data["current_channel"] = server.default_channelprint(server.channel_list)
def on_client_disconnect(server : WebsocketServer,
client : WebsocketClient) -> None:
# Remove the client from the channel it is currently in.
client.data["current_channel"]["users"].remove(client.get_id())print(server.channel_list)
def on_client_data(server : WebsocketServer,
client : WebsocketClient,
data) -> None:
# Echo client's message.
print("Received from client:", data)
server.send_string(client.get_id(), data)server = WebsocketServer("192.168.1.2", 3630,
client_buffer_size = 1024,
pass_data_as_string = True,
daemon_handshake_handler = False, # if set to True, main process
# will exit immediately. Be sure to
# create an endless loop after
# server.start() has been called.
debug = True)# You can set your own variables to server like below:
server.channel_list = {
"general" : {
"users" : []
},
"news" : {
"users" : []
}
}
server.default_channel = server.channel_list["general"]server.set_special_handler("client_connect", on_client_connect)
server.set_special_handler("client_disconnect", on_client_disconnect)
server.set_special_handler("client_data", on_client_data)server.start()
```# Installation
Install via `pip`:```
pip install pywebsocket
```Or you can install manually by cloning this repo and running this command:
```
python3 setup.py install
```# Documentation
Please refer to [here](https://egebilecen.github.io/pywebsocket/namespaces.html) for documentation.---
**Notes:**
* Doesn't support **HTTPS** connection.
* Server does support receiving fragmented messages but it doesn't support sending fragmented messages.