psmb client implemented in Python
Project description
重置版本的Asyncio PSMB Client
使用高级抽象的Client
from psmb_client.stream import Client
import asyncio
host = '127.0.0.1'
port = 13880
topic = '123123123'
client_id = 1
async def handler(msg: bytes):
print(str(msg, encoding='UTF-8'))
client = Client(host, port, topic, client_id, handler)
async def main():
try:
await client.establish()
except IOError:
return
for _ in range(10):
try:
await client.send_msg(b'asdasd')
await asyncio.sleep(5)
except IOError:
break
try:
await client.close()
except BrokenPipeError:
return
asyncio.run(main())
流式、分离的Client
from psmb_client.stream import *
import asyncio
host = '127.0.0.1'
port = 13880
topic = '123123123'
subsciber_id = 1
async def start_pub() -> Publisher:
pub = Publisher(host, port, topic)
await pub.open_connection()
return pub
async def start_sub() -> Subscriber:
async def process(data: bytes):
print(str(data, 'UTF-8'))
sub = Subscriber(host, port, topic, subsciber_id, process)
await sub.open_connection()
return sub
async def main():
pub, sub = await asyncio.gather(start_pub(), start_sub())
for i in range(10):
try:
await pub.send_msg(b'asdasd')
await asyncio.sleep(5)
except IOError:
break
try:
await pub.close()
await sub.close()
except BrokenPipeError:
pass
asyncio.run(main())
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for psmb_client-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c881fb03cc5091f71bd341128224afef867a257b28fdcd784146428b718162b0 |
|
MD5 | ccca0159364d4e4e6177f3c245f3f9eb |
|
BLAKE2b-256 | aaf198ce91706c7c3f06024eedef54b12a5356cc63b06292666012944d36608a |