Websocket Client Library
Project description
Dataplicity Lomond
Tranquil WebSockets for Python.
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 "ws:" or "wss:" WebSocket URL, construct a lomond.WebSocket
object then iterate over it. This will yield an event object for each step in the connection process and for any data sent by the server.
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
File details
Details for the file lomond-0.3.3.tar.gz
.
File metadata
- Download URL: lomond-0.3.3.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 427936596b144b4ec387ead99aac1560b77c8a78107d3d49415d3abbe79acbd3 |
|
MD5 | ad456d549ca49c42b050f27ff349a2ce |
|
BLAKE2b-256 | c09eef7813c910d4a893f2bc763ce9246269f55cc68db21dc1327e376d6a2d02 |
File details
Details for the file lomond-0.3.3-py2.py3-none-any.whl
.
File metadata
- Download URL: lomond-0.3.3-py2.py3-none-any.whl
- Upload date:
- Size: 35.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df1dd4dd7b802a12b71907ab1abb08b8ce9950195311207579379eb3b1553de7 |
|
MD5 | 236e9076f7788d76f3390405b89d2eb1 |
|
BLAKE2b-256 | 0fb102eebed49c754b01b17de7705caa8c4ceecfb4f926cdafc220c863584360 |