Use stream reader and writer objects.

Section: Streams

Open a TCP connection

python
python
import asyncio

async def main():
    reader, writer = await asyncio.open_connection("example.com", 80)
    writer.write(b"GET / HTTP/1.1
Host: example.com
Connection: close

")
    await writer.drain()
    data = await reader.read(200)
    print(data.decode(errors="replace"))
    writer.close()
    await writer.wait_closed()

asyncio.run(main())
Explanation

High-level streams are convenient for simple protocol clients.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Streams
Start a TCP server
Serve client connections with async handlers.
OpenIn sheetpythonsame section
Run a subprocess with exec
Capture stdout and stderr asynchronously.
Run blocking I/O in a thread
Use `asyncio.to_thread()` for simple thread offloading.
Run a shell command asynchronously
Spawn a shell pipeline with `create_subprocess_shell()`.
Use `run_in_executor()`
Offload work with explicit loop executor integration.