RType
Public Member Functions | Public Attributes | List of all members
ClientSocket Class Reference

#include <ClientSocket.hpp>

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

Public Member Functions

 ClientSocket ()
 Constructor of ClientSocket. More...
 
 ~ClientSocket () override
 Destructor of ClientSocket. More...
 
bool init_client (const std::string &ip, int port)
 Init the client socket. More...
 
void send (Packet *packet, struct sockaddr_in dest) override
 Send a packet to the server. More...
 
void sendPacket (SplitPacket *packet, struct sockaddr_in dest) override
 Send a split packet to the server. More...
 
std::tuple< std::unique_ptr< Packet >, int > receive () override
 Receive a packet from the server. More...
 
void run () override
 Run the client socket. More...
 
std::tuple< std::unique_ptr< Packet >, int > listen_server ()
 Stop the client socket. More...
 
void init_fd_set ()
 Stop the client socket. More...
 
bool isInit () const
 isInit, check if the client is init More...
 
void setInit (bool init)
 setInit, set the client init More...
 
void splitAndSend (Packet *packet, struct sockaddr_in dest) override
 split and send a packet to the server More...
 
void receivePacketAndAddToBuffer ()
 receiivePacketAndAddToBuffer receive a packet and add it to the buffer More...
 
std::unique_ptr< PacketgetPacketFromBuffer ()
 getPacketFromBuffer get a packet from the buffer More...
 
- Public Member Functions inherited from USocket
virtual ~USocket ()=default
 Destructor of USocket. More...
 

Public Attributes

struct sockaddr_in serv_addr
 
int sockfd
 

Detailed Description

Definition at line 20 of file ClientSocket.hpp.

Constructor & Destructor Documentation

◆ ClientSocket()

ClientSocket::ClientSocket ( )

Constructor of ClientSocket.

Definition at line 18 of file ClientSocket.cpp.

References sockfd.

◆ ~ClientSocket()

ClientSocket::~ClientSocket ( )
override

Destructor of ClientSocket.

Definition at line 57 of file ClientSocket.cpp.

References sockfd.

Member Function Documentation

◆ getPacketFromBuffer()

std::unique_ptr< Packet > ClientSocket::getPacketFromBuffer ( )

getPacketFromBuffer get a packet from the buffer

Returns
a packet get from the buffer

Definition at line 164 of file ClientSocket.cpp.

◆ init_client()

bool ClientSocket::init_client ( const std::string &  ip,
int  port 
)

Init the client socket.

Parameters
ip
port
Returns
true if the client is init

Definition at line 74 of file ClientSocket.cpp.

References packet::code, packet::data, packet::data_size, MESSAGE, send(), and serv_addr.

Referenced by main().

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

◆ init_fd_set()

void ClientSocket::init_fd_set ( )

Stop the client socket.

Definition at line 416 of file ClientSocket.cpp.

References sockfd.

Referenced by run().

Here is the caller graph for this function:

◆ isInit()

bool ClientSocket::isInit ( ) const

isInit, check if the client is init

Returns
true if the client is init

Definition at line 430 of file ClientSocket.cpp.

◆ listen_server()

std::tuple< std::unique_ptr< Packet >, int > ClientSocket::listen_server ( )

Stop the client socket.

Definition at line 381 of file ClientSocket.cpp.

References sockfd.

◆ receive()

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

Receive a packet from the server.

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

Implements USocket.

Definition at line 236 of file ClientSocket.cpp.

References receivePacketAndAddToBuffer().

Here is the call graph for this function:

◆ receivePacketAndAddToBuffer()

void ClientSocket::receivePacketAndAddToBuffer ( )

receiivePacketAndAddToBuffer receive a packet and add it to the buffer

Definition at line 132 of file ClientSocket.cpp.

References sockfd.

Referenced by receive().

Here is the caller graph for this function:

◆ run()

void ClientSocket::run ( )
overridevirtual

Run the client socket.

Implements USocket.

Definition at line 328 of file ClientSocket.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 ClientSocket::send ( Packet packet,
struct sockaddr_in  dest 
)
overridevirtual

Send a packet to the server.

Parameters
packet
dest

Implements USocket.

Definition at line 101 of file ClientSocket.cpp.

References splitAndSend().

Referenced by init_client().

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

◆ sendPacket()

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

Send a split packet to the server.

Parameters
packet
dest

Implements USocket.

Definition at line 113 of file ClientSocket.cpp.

References sockfd.

◆ setInit()

void ClientSocket::setInit ( bool  init)

setInit, set the client init

Parameters
init

Definition at line 440 of file ClientSocket.cpp.

◆ splitAndSend()

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

split and send a packet to the server

Parameters
packet
dest

Implements USocket.

Definition at line 451 of file ClientSocket.cpp.

References packet::data, and packet::data_size.

Referenced by send().

Here is the caller graph for this function:

Member Data Documentation

◆ serv_addr

struct sockaddr_in ClientSocket::serv_addr

Definition at line 104 of file ClientSocket.hpp.

Referenced by init_client().

◆ sockfd

int ClientSocket::sockfd

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