Skip to content

AHAPX/websocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

websocket

Description

Simple async websocket server, using redis as broker.

Requirements

Installation

$ git clone https://github.com/AHAPX/websocket
$ cd websocket
$ pip install -r requirements.txt

Usage

$ python websocket.py -c ~/websocket.cfg

Config file

Config has ini format, i.e.

[main]
host = localhost
port = 9998
debug = false

[redis]
host = localhost
port = 6379
db = 1
channel = ws-channel

Command line arguments

  • config - path to config file
  • host - host of websocket, default=localhost
  • port - port of websocket, default=9999
  • rhost - host of redis broker, default=locahost
  • rport - port of redis broker, default=6379
  • rdb - number of redis db, default=0
  • rchannel - redis channel for subscription, default=ws-channel
  • debug - debug mode

Testing

$ python -m unittest

API

Server

Websocket server subscribes to channel and wait messages. Message must be valid JSON. It should consist keys:

  • message - required, text or JSON
  • tags - list of tags, if it exists, websocket will send message only for clients with any tag from list

Client

Test connection

Send "ping" and you will receive "pong", if connection is ok

Subscribe to tags

When connection is established client should send its tags, i.e.

{
  "tags": ["tag1", "tag2"],
}

After that if server sends message to tag1, your client will receive it.

About

simple async websocket server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages