Member-only story

Implement a socket-based service in Python with socketserver

John Raines
9 min readFeb 14, 2021
Photo by Neven Krcmarek on Unsplash

You don’t need an HTTP application to make a service. Depending on your requirements, you might not need anything besides Python’s standard library. Implementing a socket-based service using the Python standard library socketserver module is straightforward with minimal introduction, which I plan to provide here.

Quick definition of terms, here. When I say service, in our current context I mean a program that accepts network-protocol connections from other (potentially remote) processes and handles their requests. When I first started creating services, I remember thinking I need an endpoint that I can hit with a request to [get something done]. That’s about it.

What I’ll cover

  • How does (what I’m calling) a socket-based service differ from an HTTP app?
  • What are the parts of a socket-based service?
  • What’s a basic implementation?
  • How about an async implementation?
  • What else might I consider?

How does this differ from an HTTP application?

What I’m calling a “socket-based service” is a lower-level network application than an HTTP app. In truth, HTTP applications are socket-based services because HTTP (HyperText…

--

--

John Raines
John Raines

Written by John Raines

For money, I’m a software engineer who primarily works in machine learning platform design. For free, I read fantasy novels and raise children (my own).

No responses yet