WSocket

Simple WSGI HTTP + Websocket Server, Framework, Middleware And App.

25
3
Python

Downloads
GitHub issues
GitHub forks
GitHub stars
GitHub license
Twitter


Logo

WSocket

Simple WSGI HTTP + Websocket Server, Framework, Middleware And App.

Explore the docs »

PyPI · Report Bug · Request Feature

About The Project

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.

Getting Started

This is an example of how you may give instructions on setting up your websocket connunication locally.

Installation

You can

  • Installing from PyPI
  • Download:down_arrow: and Include

Installing from PyPI

Install latest version or upgrade an already installed WSocket to the latest from PyPI.

pip install --upgrade wsocket

Download and Include

  • Visit wsocket.py.
  • Save file (ctrl+s in browser).
  • Include in your package derectory.
    my-app/
    ├─ hello_world.py
    ├─ wsocket.py

Usage

  • 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. 😄😄😄

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Code and documentation are available according to the MIT License (see LICENSE).

Contact

Report Bugs - https://github.com/Ksengine/WSocket/issues/new/