Sign inSign up

anarchy/websocket

By anarchy

Updated about 10 years ago

simple async websocket server

Image
1

2.7K

anarchy/websocket repository overview

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.

Tag summary

Content type

Image

Digest

Size

31.5 MB

Last updated

about 10 years ago

docker pull anarchy/websocket