Midnight Sun Firmware
Loading...
Searching...
No Matches
ClientConnection

Class that represents a connection between the server and a client. More...

#include <client_connection.h>

Collaboration diagram for ClientConnection:

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
 
Serverserver
 

Detailed Description

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

Constructor & Destructor Documentation

◆ ClientConnection()

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

Parameters
serverThe server that this client will be connected to

◆ ~ClientConnection()

Destructs a ClientConnection object.

If using TCP this closes the existing socket connection

Member Function Documentation

◆ acceptClient()

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

Parameters
listeningSocketThe listening sockets FD

◆ getClientAddress()

std::string getClientAddress ( ) const

Gets the clients address.

Returns
The clients address

◆ getClientName()

std::string getClientName ( ) const

Gets the clients name.

Returns
The clients name

◆ getClientPort()

int getClientPort ( ) const

Gets the clients port.

Returns
The clients port

◆ getSocketFd()

int getSocketFd ( ) const

Gets the clients socket FD.

Returns
The clients socket FD

◆ isConnected()

bool isConnected ( )

Gets the clients connection status.

Returns
TRUE if the client is connected FALSE if the client is disconnected

◆ sendMessage()

void sendMessage ( const std::string &  message)

Sends a message to the client.

Parameters
messageString message to be sent

◆ setClientName()

void setClientName ( const std::string &  name)

Sets the clients name.

Parameters
nameThe new client name

Member Data Documentation

◆ m_clientAddress

struct sockaddr_in m_clientAddress
private

The clients address

◆ m_clientName

std::string m_clientName
private

The clients name

◆ m_clientPort

int m_clientPort
private

The clients port which it is connected on

◆ m_clientSocket

int m_clientSocket
private

The clients file descriptor (FD)

◆ m_isConnected

std::atomic<bool> m_isConnected
private

Atomic flag indicating whether the client is connected

◆ server

Server* server
private

Pointer to the server instance


The documentation for this class was generated from the following files: