RType
Classes | Public Member Functions | List of all members
ServerSocket Class Reference

#include <ServerSocket.hpp>

Inheritance diagram for ServerSocket:
Inheritance graph
[legend]
Collaboration diagram for ServerSocket:
Collaboration graph
[legend]

Public Member Functions

 ServerSocket ()
 Constructor of ServerSocket. More...
 
 ~ServerSocket () override
 Destructor of ServerSocket. More...
 
void init_server (int port)
 Init the server socket. More...
 
void send (Packet *packet, struct sockaddr_in dest) override
 Send a packet to a client. More...
 
void sendPacket (SplitPacket *packet, struct sockaddr_in dest) override
 Send a split packet to a client. More...
 
void broadcast (Packet *packet)
 Broadcast a packet to all clients. More...
 
std::tuple< std::unique_ptr< Packet >, int > receive () override
 Receive a packet from a client. More...
 
void run () override
 Run the server socket. More...
 
void addClient (struct sockaddr_in client)
 Add a client to the server. More...
 
int getClientId (sockaddr_in client)
 Remove a client from the server. More...
 
struct sockaddr_in getClientAddress (int id)
 Get the client address. More...
 
void init_fd_set ()
 init_fd_set, init the fd_set More...
 
void splitAndSend (Packet *packet, struct sockaddr_in dest) override
 split and send a packet to a client More...
 
void receivePacketAndAddToBuffer ()
 receivePacketAndAddToBuffer, receive a packet and add it to the buffer More...
 
std::vector< std::tuple< int, struct sockaddr_in, std::vector< std::tuple< std::shared_ptr< SplitPacket >, timeval > >, timeval > > & getClients ()
 getClients, get the clients More...
 
std::tuple< std::unique_ptr< Packet >, int > manageClientsBuffer ()
 manageClientsBuffer, manage the clients buffer More...
 
void setNewClientConnected (int newClientConnected)
 setNewClientConnected, set the new client connected More...
 
int getNewClientId ()
 getNewClientId, get the new client id More...
 
int checkClientsDeconnection ()
 checkClientsDeconnection, check if a client is disconnected More...
 
void clientDump ()
 clientDump, dump the clients More...
 
- Public Member Functions inherited from USocket
virtual ~USocket ()=default
 Destructor of USocket. More...
 

Detailed Description

Definition at line 19 of file ServerSocket.hpp.

Constructor & Destructor Documentation

◆ ServerSocket()

ServerSocket::ServerSocket ( )

Constructor of ServerSocket.

Definition at line 17 of file ServerSocket.cpp.

◆ ~ServerSocket()

ServerSocket::~ServerSocket ( )
override

Destructor of ServerSocket.

Definition at line 50 of file ServerSocket.cpp.

Member Function Documentation

◆ addClient()

void ServerSocket::addClient ( struct sockaddr_in  client)

Add a client to the server.

Parameters
client

Definition at line 105 of file ServerSocket.cpp.

Referenced by receivePacketAndAddToBuffer().

Here is the caller graph for this function:

◆ broadcast()

void ServerSocket::broadcast ( Packet packet)

Broadcast a packet to all clients.

Parameters
packet

Definition at line 289 of file ServerSocket.cpp.

◆ checkClientsDeconnection()

int ServerSocket::checkClientsDeconnection ( )

checkClientsDeconnection, check if a client is disconnected

Returns
the client id

Definition at line 451 of file ServerSocket.cpp.

◆ clientDump()

void ServerSocket::clientDump ( )

clientDump, dump the clients

Definition at line 509 of file ServerSocket.cpp.

◆ getClientAddress()

struct sockaddr_in ServerSocket::getClientAddress ( int  id)

Get the client address.

Parameters
id
Returns
the client address

Definition at line 265 of file ServerSocket.cpp.

◆ getClientId()

int ServerSocket::getClientId ( sockaddr_in  client)

Remove a client from the server.

Parameters
client

Definition at line 123 of file ServerSocket.cpp.

Referenced by receivePacketAndAddToBuffer().

Here is the caller graph for this function:

◆ getClients()

std::vector< std::tuple< int, struct sockaddr_in, std::vector< std::tuple< std::shared_ptr< SplitPacket >, timeval > >, timeval > > & ServerSocket::getClients ( )

getClients, get the clients

Returns
a tuple with the client id, the client address, the client buffer and the client timeout

Definition at line 265 of file ServerSocket.cpp.

◆ getNewClientId()

int ServerSocket::getNewClientId ( )

getNewClientId, get the new client id

Definition at line 497 of file ServerSocket.cpp.

◆ init_fd_set()

void ServerSocket::init_fd_set ( )

init_fd_set, init the fd_set

Definition at line 232 of file ServerSocket.cpp.

Referenced by run().

Here is the caller graph for this function:

◆ init_server()

void ServerSocket::init_server ( int  port)

Init the server socket.

Parameters
port

Definition at line 63 of file ServerSocket.cpp.

Referenced by main().

Here is the caller graph for this function:

◆ manageClientsBuffer()

std::tuple< std::unique_ptr< Packet >, int > ServerSocket::manageClientsBuffer ( )

manageClientsBuffer, manage the clients buffer

Returns
a tuple with the packet and the size of the packet

Definition at line 379 of file ServerSocket.cpp.

◆ receive()

std::tuple< std::unique_ptr< Packet >, int > ServerSocket::receive ( )
overridevirtual

Receive a packet from a client.

Returns
a tuple with the packet and the size of the packet

Implements USocket.

Definition at line 140 of file ServerSocket.cpp.

References receivePacketAndAddToBuffer().

Here is the call graph for this function:

◆ receivePacketAndAddToBuffer()

void ServerSocket::receivePacketAndAddToBuffer ( )

receivePacketAndAddToBuffer, receive a packet and add it to the buffer

Definition at line 335 of file ServerSocket.cpp.

References addClient(), getClientId(), and setNewClientConnected().

Referenced by receive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

void ServerSocket::run ( )
overridevirtual

Run the server socket.

Implements USocket.

Definition at line 241 of file ServerSocket.cpp.

References init_fd_set().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send()

void ServerSocket::send ( Packet packet,
struct sockaddr_in  dest 
)
overridevirtual

Send a packet to a client.

Parameters
packet
dest

Implements USocket.

Definition at line 79 of file ServerSocket.cpp.

References splitAndSend().

Here is the call graph for this function:

◆ sendPacket()

void ServerSocket::sendPacket ( SplitPacket packet,
struct sockaddr_in  dest 
)
overridevirtual

Send a split packet to a client.

Parameters
packet
dest

Implements USocket.

Definition at line 89 of file ServerSocket.cpp.

◆ setNewClientConnected()

void ServerSocket::setNewClientConnected ( int  newClientConnected)

setNewClientConnected, set the new client connected

Parameters
newClientConnected

Definition at line 487 of file ServerSocket.cpp.

Referenced by receivePacketAndAddToBuffer().

Here is the caller graph for this function:

◆ splitAndSend()

void ServerSocket::splitAndSend ( Packet packet,
struct sockaddr_in  dest 
)
overridevirtual

split and send a packet to a client

Parameters
packet
dest

Implements USocket.

Definition at line 301 of file ServerSocket.cpp.

References packet::data_size.

Referenced by send().

Here is the caller graph for this function:

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