Asyncio TCP Multiplexer
Project description
async_multiplexer
async_multiplexer is a TCP Multiplexer based on Mplex protocol, but simplified. It is intended for creating mutiple streams in parallel on top of a same TCP connection.
Installation
pip install async-multiplexer
Usage
Client
import asyncio
from async_multiplexer import open_multiplexer_context
async def echo_client():
async with open_multiplexer_context("127.0.0.1", 7777) as multiplexer:
stream_echo_1 = await multiplexer.multiplex("echo.1")
stream_echo_2 = await multiplexer.multiplex("echo.2")
await stream_echo_1.write(b"echo.1")
await stream_echo_2.write(b"echo.2")
if __name__ == "__main__":
asyncio.run(echo_client())
Server
import asyncio
from async_multiplexer import bind_multiplex_listener_context
async def handler(stream):
data = await stream.read()
print(data)
async def echo_server():
async with bind_multiplex_listener_context("127.0.0.1", 7777) as listener:
listener.set_handler("echo.1", handler)
listener.set_handler("echo.2", handler)
await asyncio.sleep(10)
if __name__ == "__main__":
asyncio.run(echo_server())
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
Built Distribution
File details
Details for the file async_multiplexer-0.1.0.tar.gz
.
File metadata
- Download URL: async_multiplexer-0.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32a642790b5ea46830cb174019c9784c7e3e6005fcf461a4f5d68b1f0c7d5562 |
|
MD5 | 345c145b33c2873e2974486845251d29 |
|
BLAKE2b-256 | 094ee7c42803dee68e62cd3030fea20a3184459044326554d7434b97c0e318f5 |
File details
Details for the file async_multiplexer-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: async_multiplexer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c26cda3f5455e89009be65ebc4c1ec980629f23d29d1ddf89e1bb1579e5b554 |
|
MD5 | 610f02de9742893029eb562f5cc59090 |
|
BLAKE2b-256 | bc8719d50ac8aab36097db7022d8453fb55d8fc7e4e0ea48ceae9cf1a12c0f90 |