# Socket Programming in Python (Guide)

DevFeed: [Socket Programming in Python (Guide)](<https://devfeed.tech/articles/socket-programming-in-python-guide-110732.md>)

Original publisher: [Read original article](<https://realpython.com/python-sockets/>)

Author: Nathan Jennings

Published: 2026-10-31T14:00:00Z

Content type: tutorial

Language: en

Sources: [Real Python](<https://devfeed.tech/sources/real-python.md>)

Topics: [Python](<https://devfeed.tech/topics/python.md>), [async](<https://devfeed.tech/topics/async.md>), [Exception handling](<https://devfeed.tech/topics/exception-handling.md>), [Learning](<https://devfeed.tech/topics/learning.md>)

Tags: [blocking](<https://devfeed.tech/tags/blocking.md>), [client](<https://devfeed.tech/tags/client.md>), [guide](<https://devfeed.tech/tags/guide.md>), [multiple](<https://devfeed.tech/tags/multiple.md>), [python](<https://devfeed.tech/tags/python.md>), [server](<https://devfeed.tech/tags/server.md>), [socket](<https://devfeed.tech/tags/socket.md>)

## AI overview

The tutorial builds Python TCP client and server examples, starting with a blocking echo server using `socket()`, `bind()`, `listen()`, `accept()`, and `sendall()`. It explains that TCP provides reliable, in-order delivery, while `recv()` may return fewer bytes than requested, so applications must track partial reads and writes. For multiple connections, it uses nonblocking sockets and `selectors` to monitor readiness and maintain per-connection buffers; this event-loop approach is synchronous and its suitability depends on workload. A later design adds a `Message` class and an application protocol: a two-byte length prefix, followed by a UTF-8 JSON header with content metadata, then the payload. The excerpt also covers catching socket-related `OSError`s, connection timeouts, and closing idle connections, while noting that TCP itself does not define message boundaries. The source is an excerpt and ends during the protocol implementation discussion.

## Source excerpt

Build a Python socket server and client from scratch, then extend it to handle multiple connections at once without blocking.