Websocket Client Library
Project description
Dataplicity Lomond
Tranquil WebSockets for Python. Docs
Lomond is a Websocket client which turns a websocket connection in to an orderly stream of events. No threads or callbacks necessary.
How to Use
To connect to a WebSocket URL construct a WebSocket
object, then iterate over it to generate an orderly sequence of events.
You will receive a Binary
or Text
event when the server sends you a message,
you may send a message with the send_binary
or send_text
methods.
Example
The following is a silly example that connects to a websocket server (in this case a public echo server), and sends a string of text every 5 seconds.
from lomond import WebSocket
websocket = WebSocket('wss://echo.websocket.org')
for event in websocket:
if event.name == 'poll':
websocket.send_text('Hello, World')
elif event.name == 'text':
print(event.text)
Events
A successful websocket connection will result in a series of events such as the following:
┌──────────────────────┐
│ Connecting │ Contacting server
└──────────────────────┘
│
▼
┌──────────────────────┐ Connected to server (but
│ Connected │ not yet sent data)
└──────────────────────┘
│
▼
┌──────────────────────┐ Negotiated Websocket
│ Ready │ handshake
└──────────────────────┘
│ ┌───────────┐
│ │ │
▼ ▼ │
┌──────────────────────┐ │ Send and receive
│ Binary / Text / Poll │──┘ application data
└──────────────────────┘
│
▼
┌──────────────────────┐ Websocket close
│ Closed │ handshake
└──────────────────────┘
│
▼
┌──────────────────────┐
│ Disconnected │ Disconnected TCP/IP
└──────────────────────┘ connection to server
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for lomond-0.1.16a4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e18c54d350653349ff29dd69508925b2d0f96959f5630ac89e62b0649defba97 |
|
MD5 | f7b79dec5601b51103d8b328ba442ac8 |
|
BLAKE2b-256 | 73ecd353d5a7addea42c70cd60aa409493a5a9a622917418acba9e49a65141f7 |