mirror of
https://github.com/HiMeditator/auto-caption.git
synced 2026-02-10 17:44:48 +08:00
67 lines
1.7 KiB
Plaintext
67 lines
1.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4604aefd",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Received: {\"message\":\"Electron Initialized\"}\n",
|
|
"Received: {\"command\":\"process_data\",\"payload\":{\"some\":\"data\"}}\n",
|
|
"Client disconnected\n",
|
|
"Received: {\"message\":\"Electron Initialized\"}\n",
|
|
"Received: {\"command\":\"process_data\",\"payload\":{\"some\":\"data\"}}\n",
|
|
"Client disconnected\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import asyncio\n",
|
|
"import websockets\n",
|
|
"import nest_asyncio\n",
|
|
"\n",
|
|
"# 应用补丁,允许在 Jupyter 中运行嵌套事件循环\n",
|
|
"nest_asyncio.apply()\n",
|
|
"\n",
|
|
"async def handle_client(websocket, path=\"/\"):\n",
|
|
" try:\n",
|
|
" async for message in websocket:\n",
|
|
" print(f\"Received: {message}\")\n",
|
|
" await websocket.send(f\"Echo: {message}\")\n",
|
|
" except websockets.exceptions.ConnectionClosed:\n",
|
|
" print(\"Client disconnected\")\n",
|
|
"\n",
|
|
"start_server = websockets.serve(handle_client, \"localhost\", 8765)\n",
|
|
"\n",
|
|
"asyncio.get_event_loop().run_until_complete(start_server)\n",
|
|
"asyncio.get_event_loop().run_forever()"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "mystd",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.12"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|