Midnight Sun Firmware
|
Class that represents a connection between the server and a client. More...
#include <client_connection.h>
Public Member Functions | |
ClientConnection (Server *server) | |
Constructs a ClientConnection object. More... | |
~ClientConnection () | |
Destructs a ClientConnection object. More... | |
bool | acceptClient (int listeningSocket) |
Accepts a client on the listening socket. More... | |
void | sendMessage (const std::string &message) |
Sends a message to the client. More... | |
std::string | getClientName () const |
Gets the clients name. More... | |
void | setClientName (const std::string &name) |
Sets the clients name. More... | |
int | getClientPort () const |
Gets the clients port. More... | |
int | getSocketFd () const |
Gets the clients socket FD. More... | |
std::string | getClientAddress () const |
Gets the clients address. More... | |
bool | isConnected () |
Gets the clients connection status. More... | |
Private Attributes | |
std::atomic< bool > | m_isConnected |
int | m_clientPort |
int | m_clientSocket |
struct sockaddr_in | m_clientAddress |
std::string | m_clientName |
Server * | server |
Class that represents a connection between the server and a client.
This class is responsible for managing a single client connection, monitoring client activity, and sending messages between the server and the client
ClientConnection | ( | Server * | server | ) |
Constructs a ClientConnection object.
Initializes the client connection with the server. The constructor sets up internal variables and prepares the client to accept and communicate
server | The server that this client will be connected to |
~ClientConnection | ( | ) |
Destructs a ClientConnection object.
If using TCP this closes the existing socket connection
bool acceptClient | ( | int | listeningSocket | ) |
Accepts a client on the listening socket.
This sets the client socket as a non-blocking FD. The server shall add the client socket to the EPOLL list for listening
listeningSocket | The listening sockets FD |
std::string getClientAddress | ( | ) | const |
Gets the clients address.
std::string getClientName | ( | ) | const |
Gets the clients name.
int getClientPort | ( | ) | const |
Gets the clients port.
int getSocketFd | ( | ) | const |
Gets the clients socket FD.
bool isConnected | ( | ) |
Gets the clients connection status.
void sendMessage | ( | const std::string & | message | ) |
Sends a message to the client.
message | String message to be sent |
void setClientName | ( | const std::string & | name | ) |
Sets the clients name.
name | The new client name |
|
private |
The clients address
|
private |
The clients name
|
private |
The clients port which it is connected on
|
private |
The clients file descriptor (FD)
|
private |
Atomic flag indicating whether the client is connected
|
private |
Pointer to the server instance