Files
iovi-network/EchoServer.h
T
2026-06-17 21:11:25 +03:00

40 lines
1.5 KiB
C++

/**
* This is the Server's menu.
* It says: "I have a socket, a port, I can be created, I can be destroyed, I can start, and
* I have a helper to talk to clients." This short resume doesn't say how Server does any of that.
*/
#ifndef IOVI_NETWORK_ECHO_SERVER_H
#define IOVI_NETWORK_ECHO_SERVER_H
#include "NetworkConfig.h" // We need the rulebook
#include <string>
#include <thread>
class EchoServer {
SOCKET_TYPE serverSocket; // The main walkie-talkie
int port; // The channel number
// this helper function belongs to the class itself,
// not to a specific server object. Threads love static
static void handleClient(SOCKET_TYPE clientSocket);
public:
// Constructor: Runs when the server is born
explicit EchoServer(int p);
// Destructor: Runs when the server is destroyed (cleans up)
~EchoServer();
// The main action: Starts listening
// It has a while(true) loop. There is no break; and no return; inside that loop.
// Normally, a function is like a hallway: you walk in, do some work, and walk out the other end
// (which is called "returning"). But start() function has a brick wall at the end of the hallway.
// It will loop forever. CLion warns "Wait, this function never finishes! Is that a mistake?"
// We add [[noreturn]]. This is a "Warning Label" you stick on the function. It tells the compiler:
// "I know this never finishes. That is on purpose. Stop worrying."
[[noreturn]] void start();
};
#endif // IOVI_NETWORK_ECHO_SERVER_H