July 10th, 2024

Implementing a Single-Threaded Blocking Bare Bones TCP/IP Server

The article explains creating a single-threaded TCP/IP server in Java, covering port listening, client connections, message handling, and server behavior. It discusses networking concepts and demonstrates concurrent client connections.

Read original articleLink Icon
Implementing a Single-Threaded Blocking Bare Bones TCP/IP Server

This article discusses the implementation of a single-threaded blocking TCP/IP server in Java. The code provided demonstrates how to create a basic server that listens on a specific port, accepts incoming client connections, reads messages from clients, and echoes them back. The server uses streams for communication, converting byte streams to character streams for text-based data exchange. The article explains the concepts of IP addresses, ports, and sockets in network communication, highlighting their roles in facilitating communication between clients and servers. Additionally, it covers the use of Telnet for testing the server's functionality and discusses the server's single-threaded blocking behavior when handling client requests sequentially. The article concludes with a demonstration of spawning multiple client threads to send concurrent connection requests to the server. Overall, it provides a comprehensive overview of building a basic TCP/IP server and understanding the underlying networking concepts involved.

Link Icon 1 comments
By @kaz-inc - 9 months
https://github.com/kasrasadeghi/pipeline-js/blob/main/kazhtt...

I've implemented something similar for a pet project, trying to make a very concise http(s) server with raw python.

It works with bytes for speed and handles a lot of tricky edge cases I couldn't find in other implementations (like request paths that were over 16k bytes long) that I needed for my frontend. It has microsecond-level logging, a packet proxy, and a supervisor, all as separate binaries that interact.