Midnight Sun Firmware
Loading...
Searching...
No Matches
client_connection.h
1#pragma once
2
3/************************************************************************************************
4 * @file client_connection.h
5 *
6 * @brief Header file defining the ClientConnection class
7 *
8 * @date 2025-01-04
9 * @author Aryan Kashem
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <atomic>
14#include <string>
15
16/* Inter-component Headers */
17#include <arpa/inet.h>
18#include <pthread.h>
19
20/* Intra-component Headers */
21
28/* Forward declaration */
29class Server;
30
38 private:
39 std::atomic<bool> m_isConnected;
42 struct sockaddr_in m_clientAddress;
43 std::string m_clientName;
47 public:
55
61
68 bool acceptClient(int listeningSocket);
69
74 void sendMessage(const std::string &message);
75
80 std::string getClientName() const;
81
86 void setClientName(const std::string &name);
87
92 int getClientPort() const;
93
98 int getSocketFd() const;
99
104 std::string getClientAddress() const;
105
111 bool isConnected();
112};
113
Class that represents a connection between the server and a client.
Definition: client_connection.h:37
struct sockaddr_in m_clientAddress
Definition: client_connection.h:42
int getClientPort() const
Gets the clients port.
Definition: client_connection.cc:76
int m_clientPort
Definition: client_connection.h:40
std::atomic< bool > m_isConnected
Definition: client_connection.h:39
void setClientName(const std::string &name)
Sets the clients name.
Definition: client_connection.cc:72
Server * server
Definition: client_connection.h:45
bool isConnected()
Gets the clients connection status.
Definition: client_connection.cc:87
std::string m_clientName
Definition: client_connection.h:43
void sendMessage(const std::string &message)
Sends a message to the client.
Definition: client_connection.cc:57
std::string getClientName() const
Gets the clients name.
Definition: client_connection.cc:68
std::string getClientAddress() const
Gets the clients address.
Definition: client_connection.cc:21
int m_clientSocket
Definition: client_connection.h:41
int getSocketFd() const
Gets the clients socket FD.
Definition: client_connection.cc:80
bool acceptClient(int listeningSocket)
Accepts a client on the listening socket.
Definition: client_connection.cc:36
~ClientConnection()
Destructs a ClientConnection object.
Definition: client_connection.cc:32
Class that represents the central server that connects to multiple clients.
Definition: server.h:39