To start, we must define the maximum buffer size we plan to send from the client to the server and back, and we must also define the port we wish to use:
#define PORT 22000#define MAX_SIZE 0x10
It should be noted that any port number will do so long as it is above 1024, to prevent the need for privileges. In this example, the following includes are needed for the server:
#include <array>#include <iostream>#include <stdexcept>#include <unistd.h>#include <string.h>#include <sys/socket.h>#include <netinet/in.h>
The server will be defined using a class to take advantage of RAII, providing a clean method for closing the socket opened by the server when it is no longer needed. We also define three private member variables. The first variable ...