一款基于CheeseAPI的升级款Websocket插件
Project description
CheeseAPI_Websocket
介绍
一款基于CheeseAPI的升级款Websocket插件,它能够解决在多worker下websocket的通讯问题,前提是需要引入redis。
安装
目前仅支持linux python3.11,这里也推荐将python升级到3.11。
pip install CheeseAPI_Websocket
使用
CheeseAPI_Websocket是CheeseAPI的一款插件,它需要依赖于CheeseAPI才能运行。
import threading, time
from CheeseAPI import app, WebsocketClient, Response
from CheeseAPI_Websocket import websocket
app.modules = [ 'CheeseAPI_Websocket' ] # 加入模块
websocket.init() # 初始化redis连接
@app.route.websocket('/')
class Test(WebsocketClient):
...
# 创建一个线程,在非协程环境下发送Websocket
@app.handle.server_afterStartingHandle
def test():
def test0():
while True:
websocket.send('/', '你好')
time.sleep(1)
threading.Thread(target = test, daemon = True).start()
# 在协程环境下发送Websocket
@app.route.post('/websocket')
async def test1():
await websocket.async_send('/', '世界')
return Response()
if __name__ == '__main__':
app.run()
Websocket
from CheeseAPI_Websocket import websocket
websocket.init(host: IPv4 = app.server.host, port: Port = 6379, db: NonNegativeInt = 0)
初始化redis连接。
websocket.send(path: str, message: str | bytes | list | dict, sid: str | List[str] | Literal['*'] = '*')
发送消息,支持广播。
await websocket.async_send(path: str, message: str | bytes | list | dict, sid: str | List[str] | Literal['*'] = '*')
发送消息,支持广播。
websocket.close(path: str, sid: str | List[str] | Literal['*'] = '*')
关闭连接,支持广播。
await websocket.async_close(path: str, sid: str | List[str] | Literal['*'] = '*')
关闭连接,支持广播。
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file CheeseAPI_Websocket-0.1.3.tar.gz.
File metadata
- Download URL: CheeseAPI_Websocket-0.1.3.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6672cee883cb7c1892d2bb10c706967dbc0617d8539143bfb12c49e9fa17c8a5
|
|
| MD5 |
344f16686e8ad32b18136e3dd9fb4856
|
|
| BLAKE2b-256 |
f34a3f757d7915cdfe3dbc9ac89779cf67ee2db285f8ede08651d4a81e6e2689
|
File details
Details for the file CheeseAPI_Websocket-0.1.3-py3-none-any.whl.
File metadata
- Download URL: CheeseAPI_Websocket-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
573b6a0e572dc32c8abac5f5cada6564a7db895a99e68fd8c4c6bead6656d4a8
|
|
| MD5 |
daea6f18b1d6d459aa8510ce381f05c0
|
|
| BLAKE2b-256 |
716d3ce76e75119a2977512e987f1edd46df1970e23160fd7142697c72c1efb1
|