CompletedJava / TCP Sockets

TCP Socket Client & Server (IN2011)

A Java TCP stream socket client and server implementing request-response handshakes, buffered character streams, and explicit buffer flushing for IN2011 Computer Networks.

Transport:TCP Stream Sockets
I/O:Buffered Streams
Port:4567 Loopback

Overview

A client-server networking implementation built in Java for the IN2011 Computer Networks module, demonstrating TCP socket communication and stream I/O.

The Problem

Understanding transport-layer abstractions requires hands-on socket programming where buffer handling, port binding, and connection teardowns must be explicitly managed in code.

Architecture & Implementation

Built two core classes (TCPClient and TCPServer) using Java standard networking. The server binds to port 4567, blocks on accept() until a client connects, exchanges newline-delimited text payloads via character streams, and closes connection handles.

Key Challenges Solved

  • Preventing socket hangs by ensuring stream writers flush buffers immediately after write operations.
  • Handling server-side port binding and connection teardown without leaving orphaned sockets.
  • Structuring readable request-response message cycles across independent processes.

Outcomes & Verification

  • Demonstrated reliable point-to-point TCP communication with clean connection establishment and termination.
  • Documented runnable lab instructions and pushed complete source code to GitHub.