Не могу решить проблему с ошибкой после подключения клиента к серверу. Вот код сервера для Python 3.7.7:
#!/usr/bin/env python3
# WS server example
import asyncio
import websockets
#======================================================================
#Register
#======================================================================
async def Register(websocket):
remote_ip = websocket.remote_address[0] #Get client IP
print ("IP: " + remote_ip)
message="Hi. Your IP: " +remote_ip
await websocket.send(message) #Say client IP
print("==> " + str(message))
#======================================================================
#Handler
#======================================================================
async def Handler(websocket, path):
print("Client connect!")
await Register(websocket)
#try:
async for message in websocket:
print("<== " + str(message))
await websocket.send(message)
print("==> " + str(message))
#except Exception as E:
#print(str(E))
#finally:
#await asyncio.sleep(2)
#======================================================================
#MAIN
#======================================================================
print("Starting!")
start_server = websockets.serve(Handler, "0.0.0.0", 8012)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
После подключения, через 40 секунд с момента подключения, возвращается ошибка, и не имеет значения, обменивался ли клиент данными с сервер или нет.
Error in connection handler
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 827, in transfer_data
message = await self.read_message()
File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 895, in read_message
frame = await self.read_data_frame(max_size=self.max_size)
File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 971, in read_data_frame
frame = await self.read_frame(max_size)
File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 1051, in read_frame
extensions=self.extensions,
File "/usr/local/lib/python3.7/site-packages/websockets/framing.py", line 105, in read
data = await reader(2)
File "/usr/local/lib/python3.7/asyncio/streams.py", line 679, in readexactly
await self._wait_for_data('readexactly')
File "/usr/local/lib/python3.7/asyncio/streams.py", line 473, in _wait_for_data
await self._waiter
concurrent.futures._base.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/websockets/server.py", line 191, in handler
await self.ws_handler(self, path)
File "StartWB3.py", line 26, in Handler
async for message in websocket:
File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 439, in __aiter__
yield await self.recv()
File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 509, in recv
await self.ensure_open()
File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 812, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason
В чем может быть проблема? Заранее спасибо за ответы.