Simple WSGI HTTP + Websocket Server, Framework, Middleware And App.
Explore the docs »
PyPI
·
Report Bug
·
Request Feature
This is a simple library to add websocket support to WSGI.
- Server - Patched wsgiref server
- Middleware - Add websocket support to Flask, Django, Pyramid, Bottle, ...
- Handler - Websocket handler to wsgiref
- Framework - Basic websocket + WSGI web application framework
- App - Plug and play demo app.
This is an example of how you may give instructions on setting up your websocket connunication locally.
You can
- Installing from PyPI
- Download:down_arrow: and Include
Install latest version or upgrade an already installed WSocket to the latest from PyPI.
pip install --upgrade wsocket
- Visit wsocket.py.
- Save file (
ctrl+s
in browser). - Include in your package derectory.
my-app/
├─ hello_world.py
├─ wsocket.py
- Include following source on your test file(eg:-
hello_world.py
).
from wsocket import WSocketApp, WebSocketError, logger, run
from time import sleep
logger.setLevel(10) # for debugging
def on_close(self, message, client):
print(repr(client) + " : " + message)
def on_connect(client):
print(repr(client) + " connected")
def on_message(message, client):
print(repr(clent) + " : " + repr(message))
try:
client.send("you said: " + message)
sleep(2)
client.send("you said: " + message)
except WebSocketError:
pass
app = WSocketApp()
app.onconnect += on_connect
app.onmessage += on_message
app.onclose += on_close
run(app)
- Visit client.html.
- Save file (
ctrl+s
in browser). - Open it in browser(websocket supported).
- Experience the two way websocket communication. 😄😄😄
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Code and documentation are available according to the MIT License (see LICENSE).
Report Bugs - https://github.com/Ksengine/WSocket/issues/new/