Skip to main content

Makes websockets with Mongrel2 and Python super easy

Project description

Makes handling websockets with Mongrel2 and Python easy peasy.

This module was lovingly crafted for First Opinion.

Example

Typical websocket hello world type example, creating an echo server:

import os
import logging

logging.basicConfig()
rl = logging.getLogger()
rl.setLevel('DEBUG')

from m2websocket import Connection


conn = Connection("tcp://localhost:port", "tcp://localhost:port")

while True:
    req = conn.recv()
    if req.is_handshake():
        conn.reply_handshake(req)

    else:
        conn.reply_websocket(req, req.body, req.opcode)

Yup, that’s all there is to it, much easier than this example.

You can see a working example of the echo server (with a working mongrel2 conf file and python script) by looking in the example/ directory in the Github repo.

Install it

Prerequisites

You’ll need to install the mongrel2 python library from the mongrel2 source. Once you’ve cloned the source or downloaded that folder, you can install it using setup.py

$ cd /path/to/mongrel2/src/examples/python
$ python setup.py install

Then, you can install this module using pip:

pip install m2websocket

Or:

pip install git+https://github.com/firstopinion/m2websocket#egg=m2websocket

Tests are actually kind of hard to run, you need to install mongrel2 and have it load the example/mongrel2.conf configuration and then run the example/echo.py server. You also need to pip install websocket-client.

License

MIT

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

m2websocket-0.2.2.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file m2websocket-0.2.2.tar.gz.

File metadata

File hashes

Hashes for m2websocket-0.2.2.tar.gz
Algorithm Hash digest
SHA256 adbb9342d4047a9666c1b6eecae7baef9fa5385b1af5d5287fcb0cc9d65f020e
MD5 e1d9682d05434905dfa6911305acc3b6
BLAKE2b-256 ecf1c5bc65d9a071d9dfce65f2f86e55f5a1a83877227f9cd00a9fb1ae65ea72

See more details on using hashes here.

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