first commit

This commit is contained in:
2025-10-20 12:32:18 +08:00
commit 2cfd7c5a08
121 changed files with 254585 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
import asyncio
import websockets
# 定义处理 WebSocket 连接的协程
async def handle_connection(websocket, path):
# 接收客户端发送的消息
print("WebSocket connection established.")
while True:
message = await websocket.recv()
print(f"Received message: {message}")
# # # 发送响应消息给客户端
# response = f"Hello, {message}!"
# await websocket.send(response)
# 启动 WebSocket 服务端
start_server = websockets.serve(handle_connection, "192.168.0.111", 8765)
# 运行事件循环
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()