Hex
Hex

Reputation: 1

ConnectionRefusedError: [WinError 1225] The remote computer refused the network connection

I'm running this code in VS Code:

import asyncio

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

    print(f'Send: {message!r}')
    writer.write(message.encode())
    await writer.drain()

    data = await reader.read(100)
    print(f'Received: {data.decode()!r}')

    print('Close the connection')
    writer.close()
    await writer.wait_closed()

asyncio.run(tcp_echo_client('Hello World!'))

It's exactly the same in Python's original docs, but I have no idea why I get that error.

In Spyder the error's a little different: RuntimeError: asyncio.run() cannot be called from a running event loop

I also tried different IPs and ports. When I tried another IP like Google's DNS, (8.8.8.8), I encountered this another weird error: OSError: [WinError 121] The semaphore timeout period has expired

Upvotes: 0

Views: 1814

Answers (1)

Lee Poll
Lee Poll

Reputation: 1

Try running this first:

tcp_echo_server.py

Upvotes: 0

Related Questions