In this example, we will walk the reader through creating an echo server, but using TCP instead of UDP. Just like with the previous example, an echo server echoes any input to its output. Unlike the UDP example, TCP is a connection-based protocol, and thus some of the specifics of how to establish a connection and send/receive data are different in this example.
Studying an example on the TCP echo server
Server
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
For the server, we will need the following includes:
#include <array>
#include <iostream>
#include <unistd.h...