-
Notifications
You must be signed in to change notification settings - Fork 2
Appendices
The appendices section of this guide provides additional resources and information that may be useful during the development of the IRC server.
The Makefile is an important tool that is used to build the IRC server program. It specifies the compiler, flags, and rules that are used to create the executable.
To use the Makefile, open a terminal window and navigate to the directory containing the Makefile and source files. Then, enter one of the following rules:
-
make
: builds the IRC server executable -
make clean
: removes object files -
make fclean
: removes object files and the executable -
make re
: removes object files and the executable, then builds the executable again
For example, to build the IRC server executable, enter the command make in the terminal. If the program compiles successfully, the executable will be created and can be run using the command ./ircserv <port> <password>
, where <port>
is the listening port and <password>
is the connection password specified as command-line arguments.
By following these instructions, you can easily build, clean, and rebuild the IRC server program using Makefile.
The C++ 98 standard (also known as C++03) is a version of the C++ programming language that was released in 1998. It includes features such as support for namespaces, exception handling, and the STL (Standard Template Library).
For this IRC server project, you are required to develop the program using the C++ 98 standard. This means that you should use only features and libraries that are available in C++ 98 and avoid using any newer features or libraries that were introduced in later versions of C++.
To compile the program using the C++ 98 standard, you can include the flag -std=c++98
in the Makefile's CXXFLAGS
variable, like so:
CXXFLAGS = -Wall -Wextra -Werror -std=c++98
This will ensure that the compiler uses the C++ 98 standard when building the program. It is important to follow this requirement in order to ensure that the program is compatible with the C++ 98 standard and can be graded appropriately.
This is how your Makefile should be written:
SRC = ./src/*.cpp
OBJ = ${SRC:.cpp=.o}
NAME = ircserv
CXX = c++
CXXFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -rf
all : ${NAME}
${NAME} : ${OBJ}
${CXX} ${CXXFLAGS} ${OBJ} -o ${NAME}
clean :
${RM} ${OBJ}
fclean : clean
${RM} ${NAME}
re : fclean all
Once you have compiled and run the IRC server, it is important to thoroughly test and debug the program to ensure that it is functioning as intended. You can do this by using your reference client to connect to the server and perform a range of actions, such as authenticating, setting a nickname and username, joining channels, and sending and receiving messages.
As you test the program, pay close attention to any errors or issues that may arise. Use tools such as a vscode debugger, print statements, or Valgrind to identify the source of any problems and fix them. It is a good idea to test the program with multiple clients and in different scenarios to ensure that it is robust and reliable.
The following code snippets provide examples of some common tasks that may be needed when developing the IRC server. These snippets are intended to be used as a reference and can be modified or extended as needed.
- Parsing command-line arguments:
int main(int argc, char **argv)
{
if (argc != 3)
{
std::cerr << "Usage: ./ircserv <port> <password>" << std::endl;
return (1);
}
int port = atoi(argv[1]);
std::string password = argv[2];
// ...
}
- Creating a socket:
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
std::cerr << "Error: socket() failed" << std::endl;
return (1);
}
- Creating a socket address structure:
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = INADDR_ANY;
- Binding a socket to a port:
if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
{
std::cerr << "Error: bind() failed" << std::endl;
return (1);
}
- Listening for connections:
if (listen(sockfd, 10) < 0)
{
std::cerr << "Error: listen() failed" << std::endl;
return (1);
}
- Accepting a connection:
int newsockfd = accept(sockfd, (struct sockaddr *)&addr, &addrlen);
if (newsockfd < 0)
{
std::cerr << "Error: accept() failed" << std::endl;
return (1);
}
- Reading from a socket:
char buffer[1024];
int n = read(newsockfd, buffer, 1024);
if (n < 0)
{
std::cerr << "Error: read() failed" << std::endl;
return (1);
}
- Writing to a socket:
char buffer[1024];
int n = write(newsockfd, buffer, 1024);
if (n < 0)
{
std::cerr << "Error: write() failed" << std::endl;
return (1);
}
- Closing a socket:
close(sockfd);
The following resources were used as references during the development of the IRC server.
- C++ 98 Standard: ISO/IEC 14882:1998
- Socket programming tutorial: Beej's Guide to Network Programming
- IRC protocol specification: RFC 1459
- Irssi reference client: Irssi documentation
These resources provided valuable information on the C++ 98 standard, socket programming, the IRC protocol, and the Irssi client, which were all essential for completing the IRC server project.