PROJECT STUDY / NETWORKING

ft_irc

An IRC server that keeps multiple clients in conversation through channels, private messages and a shared event loop.

C++98 · Sockets · Nonblocking I/O

Repository ↗

The problem

Handle several TCP clients without blocking on one connection. Authenticate users, track channel membership and deliver messages using IRC commands.

From connection to conversation

PASS <server-password>
NICK hamza
USER hamza 0 * :Hamza
JOIN #systems
PRIVMSG #systems :Hello from my client!

PASS supplies the server password. NICK and USER identify the client. JOIN adds it to a channel. PRIVMSG routes its text to the channel's other members, or to one nickname for a direct message.

A design decision

The server uses poll() to wait for socket readiness. Per-client input buffers collect incoming fragments; output queues keep unsent bytes until the socket can accept them.

A socket edge case

A TCP read is not one IRC command. A command can arrive across several reads, and one read can contain several commands. receiveData() appends bytes and extracts complete lines. flushWrite() consumes only the number of bytes send() wrote, retaining the rest for a later writable event.

Channel delivery

cmdPrivmsg() checks that the channel exists and the sender is a member before broadcasting. It excludes the sender from that broadcast. The browser demo shows the sender's local copy beside the message received by the other client.

Try the chat demo →

A possible next iteration

Add automated tests for fragmented commands, slow readers and disconnects during broadcasts.

Explore the implementation

This walkthrough is based on commit 517d9c8. It describes source behavior rather than a personal debugging story.

Read the socket buffers ↗