Skip to main content

HTTP and Websocket both supported wsgi server

Project description

WSocket

HTTP and Websocket both supported wsgi server

Downloads

Server(WSGI) creates and listens at the HTTP socket, dispatching the requests to a handler. this is only use standard python libraries. also: this is a plugin to ServerLight Framework.

for a better experiense install servelight

###Code to create and run the server looks like this:
using bottle(install bottle before try)

#!/usr/bin/python
# -*- coding: utf-8 -*-
from bottle import request, Bottle
from wsocket import WebSocketHandler
from wsgiref.simple_server import make_server
from time import sleep

app = Bottle()

@app.route('/')
def handle_websocket():
    wsock = request.environ.get('wsgi.websocket')
    if not wsock:
        return 'Hello World!'
    while True:
        message = wsock.receive()
        print(message)
        wsock.send('Your message was: %r' % message)
        sleep(3)
        wsock.send('Your message was: %r' % message)

httpd = make_server('localhost',9001,app,handler_class=WebSocketHandler)
print('WSGIServer: Serving HTTP on port 9001 ...\n')
try:
    httpd.serve_forever()
except:
    print('WSGIServer: Server Stopped')

run this code download client.html file open it with browser see how it works! then navigate to http://localhost:9001 You can see Hello World!

Features

  • the power of websocket
  • fast ( It's very fast )
  • simple
  • lightweight (simple and lightweight )
  • WSGI ( supports web server gateway interface )
  • with web frameworks (any WSGI framework supported)

Flask, Django, Pyramid, Bottle supported

View Documentaion*

License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

WSocket-1.1.6.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distributions

WSocket-1.1.6-py3.7.egg (12.8 kB view hashes)

Uploaded Source

WSocket-1.1.6-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

WSocket-1.1.6-py2.7.egg (12.8 kB view hashes)

Uploaded Source

WSocket-1.1.6-py2-none-any.whl (9.4 kB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page