A tornado MSTP library, using WebSocket.
Project description
Tornado MSTP
A tornado MSTP library, using WebSocket.
Installation
pip install tornado_mstp
Easy Examples
See repo's directory named 'examples'.
Usage
Server
As a server-side application using tornado_mstp
. You should first create a
handler class inherited from MstpSocketHandler
:
from tornado_mstp import MstpSocketHandler
class MyMstpSocketHandler(MstpSocketHandler):
pass
There are two optional class attributes, automatic_closing_time
(default to 10) and ver
(default to "0.1"), that indicate MSTP server information
need to be set.
from tornado_mstp import MstpSocketHandler
class MyMstpSocketHandler(MstpSocketHandler):
automatic_closing_time = 15
ver = "0.1"
There is no need to worry about tornado websocket handler's on_message
method.
Each MSTP package type of message has a callback function who needs to be
implemented. For example, for segment handling:
from typing import Optional
from tornado_mstp import MstpSocketHandler
from tornado_mstp.schema import ContentType
class MyMstpSocketHandler(MstpSocketHandler):
automatic_closing_time = 15
ver = "0.1"
async def handle_segment(
self,
package_id: Optional[str] = None,
message_index: Optional[int] = None,
segment_index: Optional[int] = None,
is_end: Optional[bool] = None,
content_type: Optional[ContentType] = None,
content: Optional[str] = None
) -> None:
print(f"received content: {content}")
After implementing all callback functions, server can handle any MSTP packages as you want.
Client
As a client-side connection using tornado_mstp. You can just create an
mstpsocket_connect
using tornado_mstp.mstpsocket_connect
. It has the
same usage of tornado.websocket.websocket_connect
.
import asyncio
from tornado_mstp import mstpsocket_connect
def callback(message):
print(message)
async def main():
conn = mstpsocket_connect(
url="mstp://other-mstp-server",
on_message_callback=callback
)
await conn
if __name__ == '__main__':
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 Distribution
Built Distribution
Hashes for tornado_mstp-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf26d9c71dcd7bee0cf510b602ea45f1f64d0506d8d03c54322be2d2d3ec4550 |
|
MD5 | e573b017bb90d2e4bdc5ee7c10b2396a |
|
BLAKE2b-256 | 74b864985795aa73a39de95037d117e33e4f18153389eaddb99cf8f1f4398043 |