Git Product home page Git Product logo

python-wss's Introduction

python-wss

Simple python secure websocket server/client with optional authentication built in.

This is just a simple wrapper around autobahn that removes the need to write a bunch of boiler plate code if you just want a simple and secure server client to send messages back and forth. It has optional diffie-helman-based authentication (what? dh isn't for authentication?).

You still need to create your own ssl certs and keys. You can follow this guide on how to create a locally signed cert/key combo:

https://tripzero.io/general/secure-websocket-server-using-autobahn-and-trollius-asyncio/

You can also use letsencrypt.org to create cert/keys.

basic usage:

import wss
import trollius as asyncio

loop = asyncio.get_event_loop()

server =  wss.Server(port=1234, usessl=True, sslcert="path/to/cert.crt", 
                     sslkey="path/to/server.key", auth=None)

def onTextMessage(server, msg, client):
	print("got message from client:", msg)

def onBinaryMessage(server, msg, client):
	print("got binary message")

server.onMessage = onTextMessage
server.onBinaryMessage = onBinaryMessage

@asyncio.coroutine
	def sendData():
		while True:
			try:
				print("trying to broadcast...")
				s.broadcast("{'hello' : 'world' }")
			except:
				exc_type, exc_value, exc_traceback = sys.exc_info()
				traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
				traceback.print_exception(exc_type, exc_value, exc_traceback,
	                          limit=2, file=sys.stdout)

			yield asyncio.From(asyncio.sleep(30))

loop.create_task(sendData())

server.start()
loop.run_forever()

python-wss's People

Contributors

tripzero avatar bsmg1h avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.