bricks/examples/echo.ws

28 lines
784 B
Plaintext
Raw Permalink Normal View History

2024-04-26 12:54:51 +08:00
# ws_data 客户端传过来的数据
# ws_pool 保存所有链接
# register(id)
# 注册自己id必须唯一
# sendto(data, id=None)
# 发送消息给客户端当id为空时发送给当前链接的客户端否则发送给id指定的客户端
# is_online(id)
# 检查id指定的客户端是否在线
2024-04-28 11:18:17 +08:00
# user = await get_user()
2024-04-29 17:36:36 +08:00
userid = 'kkkkk'
ws_pool.register(userid)
2024-04-26 12:54:51 +08:00
resp = 'resp=' + ws_data
2024-04-29 17:36:36 +08:00
if ws_pool.is_online(userid):
print(f'{userid=} is online')
ret = {
'efew':1,
'g':3
}
r = await ws_pool.sendto(ret, userid)
print(f'{ret=} send return {r}')
else:
print(f'{userid=} is not online')
print(f'{resp=}, {ws_pool.get_data()=}')
2024-04-26 12:54:51 +08:00
await ws_pool.sendto(resp)
2024-04-28 11:18:17 +08:00
# if ws_pool.is_online('bington'):
# await ws_pool.sendto(resp, 'bington')