匯入了websockets模塊,用https://pypi.org/project/websockets/主頁上的客戶端和服務端范例代碼跑了一下
服務端
import asyncio
import websockets
async def echo(websocket, path):
async for message in websocket:
await websocket.send(message)
asyncio.get_event_loop().run_until_complete(
websockets.serve(echo, '192.168.0.100', 8765))
asyncio.get_event_loop().run_forever()
客戶端
#!/usr/bin/env python
import asyncio
import websockets
async def hello(uri):
async with websockets.connect(uri) as websocket:
await websocket.send("Hello world!")
await websocket.recv()
asyncio.get_event_loop().run_until_complete(
hello('ws://192.168.0.100:8765'))
server和client都能正常運行
但是client一旦運行超server發送資料的時候,server就會報例外
例外資訊:
Accept failed on a socket
socket: <asyncio.TransportSocket fd=424, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.0.100', 8765)>
Traceback (most recent call last):
File "D:\Python38\lib\asyncio\proactor_events.py", line 801, in loop
conn, addr = f.result()
File "D:\Python38\lib\asyncio\windows_events.py", line 808, in _poll
value = callback(transferred, key, ov)
File "D:\Python38\lib\asyncio\windows_events.py", line 557, in finish_accept
return conn, conn.getpeername()
OSError: [WinError 10014] 系統檢測到在一個呼叫中嘗試使用指標引數時的無效指標地址。
Task exception was never retrieved
future: <Task finished name='Task-3' coro=<IocpProactor.accept.<locals>.accept_coro() done, defined at D:\Python38\lib\asyncio\windows_events.py:559> exception=OSError(10014, '系統檢測到在一個呼叫中嘗試使用指標引數時的無效指標地址。', None, 10014, None)>
Traceback (most recent call last):
File "D:\Python38\lib\asyncio\windows_events.py", line 562, in accept_coro
await future
File "D:\Python38\lib\asyncio\proactor_events.py", line 801, in loop
conn, addr = f.result()
File "D:\Python38\lib\asyncio\windows_events.py", line 808, in _poll
value = callback(transferred, key, ov)
File "D:\Python38\lib\asyncio\windows_events.py", line 557, in finish_accept
return conn, conn.getpeername()
OSError: [WinError 10014] 系統檢測到在一個呼叫中嘗試使用指標引數時的無效指標地址。
求指教
uj5u.com熱心網友回復:
python版本是3.8最新版轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/93747.html
上一篇:python小白求教:如何在jupyter中通過指令,用spyder打開一個py格式的檔案呢?
下一篇:windows系統
