We'll develop two programs, a client and a server. The server will start and listen on a specific port that is ready to accept an incoming connection. The client will start and connect to the server identified by an IP and a port number:
- With the Docker image running, open a shell and create a new file, clientTCP.cpp. Let's add some headers and constants that we'll need later:
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#include <iostream>constexpr unsigned int SERVER_PORT = 50544;constexpr unsigned int MAX_BUFFER = 128;
- Let's start writing the main method now. We start by initializing socket and getting ...