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
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()`.