The ft_irc project aims to help students gain proficiency in network programming, socket usage, and multi-client management. By developing a server that complies with the IRC protocol, students learn the fundamentals of real-time communication systems and gain experience in building an efficient and robust architecture using C++.

- What is an Endpoint?
- What is a Socket?
- Network and Communication Fundamentals
- Concurrency and Scalability
- Application Architecture and Logic
- Supported IRC Commands
- Testing the Server
- Error Handling Strategy
- Project Structure
- Future Improvements
In software development, especially in the context of web services (APIs), an endpoint refers to a specific URL where communication occurs between a client and a server. Each endpoint performs a specific function.
π§ Technically speaking:
Each endpoint is defined by a specific HTTP route and usually paired with an HTTP method (GET, POST, PUT, DELETE).
Example:
Action | Endpoint | URL | Method |
---|---|---|---|
List Products | GET /api/products/ | /api/products/ |
GET |
Product Detail | GET /api/products/ID | /api/products/123/ |
GET |
Add New Product | POST /api/products/ | /api/products/ |
POST |
Update Product | PUT /api/products/ID | /api/products/123/ |
PUT |
Delete Product | DELETE /api/products/ID | /api/products/123/ |
DELETE |
π§ In Simple Terms:
Endpoints are like the buttons on a website. For example:
- If there's a "Sign Up" button: there's an endpoint like
/api/register/
- If there's an "Add to Cart" button: it corresponds to
/api/cart/add/
π¦ For Backend Developers:
An endpoint typically includes:
- URL:
/api/user/login/
- HTTP Method:
POST
- Request Data: JSON object with user credentials
- Response Data: Success or error message (and often a token)
A socket is a communication endpoint used for exchanging data over a network between two devices (typically computers).
It allows one computer to connect and talk to another over the internet or a local network.
π‘ Technically:
A socket is defined by:
- IP Address (which computer?)
- Port Number (which application?)
So, a socket = (IP address + Port)
π§± How Sockets Work:
- The server starts listening on a specific port (e.g.,
127.0.0.1:5000
) - The client tries to connect to that IP and port
- Once connected, data is exchanged between the two
- After the communication ends, the socket is closed
π Types of Sockets:
Type | Description |
---|---|
TCP Socket | Reliable, ordered communication (e.g., HTTP, FTP) |
UDP Socket | Fast but unreliable (e.g., video games, VoIP) |
Since the IRC protocol requires user sessions and reliable message delivery, TCP sockets are used.
This is a basic communication model where a central server provides services to multiple clients. In IRC systems, all message traffic is routed through the server.
- TCP (Transmission Control Protocol) is used in IRC systems for reliable, ordered, and lossless data transmission.
- It's connection-oriented and ensures data integrity, making it suitable for real-time chat applications.
-
A socket is an endpoint defined by an IP address and a port number.
-
Basic operations:
- Create a socket (
socket()
) - Bind to an address (
bind()
) - Listen for connections (
listen()
) - Accept new connections (
accept()
) - Send/receive data (
send()
,recv()
)
- Create a socket (
IRC is a text-based protocol. Messages:
- Are serialized into bytes before transmission,
- Then parsed and interpreted by the server.
- Example:
PRIVMSG #channel :Hello there!
sends a message to all users in#channel
.
A real IRC server must handle hundreds or thousands of clients simultaneously and efficiently.
-
Goal: Handle multiple connections in a single thread, avoiding the overhead of spawning one thread per client.
-
Techniques:
select
poll
epoll
(Linux)kqueue
(macOS/BSD)
This project typically uses
poll()
for portability and simplicity.
- The server runs a continuous loop monitoring for events (incoming data, disconnection, etc.).
- When an event occurs, the appropriate handler function is executed.
- This enables a reactive and modular design.
- Functions like
recv()
oraccept()
return immediately if there's no data. - This ensures the server can continue processing other clients without being blocked.
-
Each client connection has a state:
- e.g., Unregistered β Registered β Joined Channel
-
Example: After
NICK
andUSER
commands, the user becomes "registered".
-
The server must conform to IRC RFC 2812 standards.
-
This includes handling valid commands, parameter counts, reply formats, and numeric codes.
-
Example:
:server 001 nick :Welcome to the Internet Relay Network
-
Users can have different permissions:
- Channel operators can kick, ban, or change topic.
-
The server validates permissions before executing privileged actions.
-
The server determines how to route messages:
- To another user (private message)
- To all users in a channel
-
This may involve message queuing or direct delivery depending on the design.
The following commands are implemented in compliance with the IRC protocol (RFC 2812). Each command follows strict syntax, validation, and state logic.
Command | Description |
---|---|
NICK |
Sets or changes the nickname of a user |
USER |
Registers a new user with username and real name |
JOIN |
Joins one or more channels (creates channel if not exists) |
PART |
Leaves a channel |
PRIVMSG |
Sends a private message to a user or channel |
NOTICE |
Sends a non-reply message (no automatic replies like PRIVMSG ) |
PING |
Ping request to check connection health |
PONG |
Ping response |
QUIT |
Disconnects the user with an optional message |
MODE |
Changes or queries channel/user modes |
TOPIC |
Gets or sets the topic of a channel |
KICK |
Removes a user from a channel (requires operator status) |
Netcat: Netcat (nc) is a lightweight, command-line based networking tool used for testing network connections, transferring data, and listening on ports. It can act as both a client and a server.
π§ What is it used for?
- Establishing TCP or UDP connections
- Listening on a port (acting like a server)
- Transferring files
- Sending and receiving data over sockets to test network applications
$ nc 127.0.0.1 6667
NICK mynick
USER mynick 0 * :Real Name
JOIN #test
PRIVMSG #test :Hello everyone!
Expected response:
:ircserv 001 mynick :Welcome to the IRC server!
You can also write automated test scripts using Python (e.g., with socket
and unittest
) to simulate multiple clients joining, messaging, and disconnecting.
The server gracefully handles and responds to user mistakes or protocol violations:
- β Invalid command format β numeric error codes
- β Nickname already in use β
433 ERR_NICKNAMEINUSE
- β Not registered β
451 ERR_NOTREGISTERED
- β Trying to join without USER/NICK β rejected with reason
All socket operations are wrapped in exception-safe logic. Disconnected clients are cleaned up and removed from internal structures (pollfd
, nickmap, channels, etc.).
ft_irc/
β
βββ Commands/
β βββ Invite.cpp / Invite.hpp # Invite user
β βββ Join.cpp / Join.hpp # Join channel
β βββ Kick.cpp / Kick.hpp # Kick user
β βββ Mode.cpp / Mode.hpp # Channel modes
β βββ Nick.cpp / Nick.hpp # Nickname operations
β βββ Part.cpp / Part.hpp # Leave channel
β βββ Pass.cpp / Pass.hpp # Password authentication
β βββ Privmsg.cpp / Privmsg.hpp # Send message
β βββ Quit.cpp / Quit.hpp # Disconnect from serve
β βββ Topic.cpp / Topic.hpp # Channel topic
β βββ User.cpp / User.hpp
β
βββ Modes/
β βββ Invite.cpp / Invite.hpp # +i mode (invite-only)
β βββ Key.cpp / Key.hpp # +k mode (password-protected)
β βββ Limit.cpp / Limit.hpp # +l mode (user limit)
β βββ Modes.cpp / Modes.hpp # Main mode handler
β βββ Op.cpp / Op.hpp # +o mode (channel operator)
β βββ Topic.cpp / Topic.hpp # +t mode (topic restrictions)r
βββ main.cpp # Main entry point
βββ Server.cpp/hpp # Core server class
βββ Commands.cpp/hpp # Command handler