Open source · Featured · 2023

P2P Chat Application.

Sockets, from scratch.

RoleAuthor & maintainer
ShippedDecember 2023
StackPython · Socket Programming · MongoDB +1
abdelmaksoud.dev
presents
Admit one
github.com
P2P Chat Application

Act I

The challenge

Most chat apps quietly route everything through a server. For a networks course, the whole point was to not do that: real peer-to-peer messaging on raw sockets, with a registry only for discovery and a heartbeat tracking who’s actually online.

Act II

What I built

A Python CLI chat built on raw sockets. A threaded central registry handles auth and discovery, but every peer also runs its own TCP server for direct one-to-one chat, presence rides a UDP heartbeat, and MongoDB-backed rooms fan messages out over UDP.

Intermission, the demo

The product, playing itself

peer Apeer BTCP / UDP, no server in between

a packet and its ack, no server in between, the whole point, in one hop

The cast

What actually makes it work

Read the card, then flip it to watch the mechanism run.

0x01

Presence protocol

A self-rescheduling one-second UDP heartbeat plus a per-user timeout reaper on the registry keeps an accurate online list without polling.

how it works

Presence protocol

0x02

Hybrid topology

The registry stays centralized for auth and discovery while messaging is decentralized, so each client is at once a TCP client and its own threaded TCP server.

how it works

Hybrid topology

0x03

UDP room fan-out

Member IP and port lists come from the registry, and room messages go out as direct datagrams to each member under registry-side locks.

how it works

UDP room fan-out
View on GitHub