In this note
  1. 01Highlights
  2. 02Server State
  3. 03Commands
  4. 04Notes
  5. 05Knowledge Points

I built this simulator to work through four things at once: reliable messaging, heartbeats as a liveness signal, authentication, and peer-to-peer file sharing.

The design puts control and bulk data on different protocols. UDP carries authentication, commands, and heartbeats. TCP carries file payloads, and only between peers.

Highlights

  • UDP control plane for auth, commands, heartbeat messages, and peer discovery.
  • TCP data plane for streaming file payloads from publishers.
  • Heartbeat pruning removes inactive peers after the timeout.
  • Server state tracks address-to-user mappings, active timestamps, and published file metadata.
  • Each client binds a TCP server to an ephemeral port and advertises that port when it publishes a file.

Server State

The server keeps four maps: address to username, username to address, client activity timestamps, and file ownership. With those it can authenticate a command, list who is online, and tell a client where to find a file.

The server does not host files. It runs closer to a directory service: once the client has the publisher address, the download goes over TCP directly between the two peers.

Commands

  • pub <file> publishes a local file if it exists.
  • get <file> asks the server for the publisher address, then opens TCP to fetch the file.
  • lap and lpf list active peers and published files.
  • sch <substr> searches published files across peers.
  • unp <file> unpublishes a file for the current user.

Notes

It started as a lab simulator. The obvious extensions are TLS, per-chunk checksums, retry backoff, and richer observability.

Knowledge Points

  • UDP is useful for lightweight control messages, but liveness and identity have to be built in the application.
  • TCP fits file transfer because it gives an ordered, reliable byte stream.
  • A heartbeat turns silence into a failure you can detect.
  • A directory server pattern coordinates peers without proxying every file payload.
  • The client needs threads: it has to accept TCP downloads while it keeps sending UDP commands.
  • Protocol commands need validation and clear error responses, or the client cannot tell what happened.
  • A production version would add stronger auth, encryption, retries, and checksums.