A
A
AlexBoss2020-07-03 12:44:04
Python
AlexBoss, 2020-07-03 12:44:04

How to handle client socket connection in asyncio?

Good afternoon. In all manuals, the connection is made through open_connection, but in case of problems with the connection, an error falls. What are socket.connect_ex counterparts from the standard library that return codes?

async def test(message):
    reader, writer = await asyncio.open_connection(
        '127.0.0.1', 8888)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan, 2020-07-04
@ruzzz

You can catch those exceptions first, which is logical for asyncio, timeout, cancellation.
And additionally base type OSError, for possible connection problems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question