Writing Web Servers from Scratch in Python Using Only TCP Sockets
Talko: An End-to-End Chat Application - Better Programming
How to build a chat app from first principles (no libraries or frameworks)Web development is possibly the most ubiquitous form of programming that exists today. Frameworks like Flask and Node.js have made writing web applications extremely accessible and hosting on sites like Heroku is a breeze. While these frameworks are powerful, many people treat them as black boxes, using them without really understanding what’s going on under the hood. In this article, we’ll crack open the black box and see how to build a real-time chat application, Talko 🌮, from first principles. We won’t use HTTP, requests, or frameworks.Figure 1: A Talko web client (left) communicating with a Talko terminal client (right).Starting with only TCP sockets, we’ll first implement a custom transfer protocol to allow our services to easily transfer messages between themselves. Then, we’ll implement two servers and a client library and use JSON-RPC on top of the transfer protocol to communicate between them. Finally, using the client library, we’ll implement the two basic clients shown in Figure 1.All working code accompanying this article can be found on my GitHub.The Talko Transfer Protocol…