Main MRPT website > C++ reference for MRPT 1.4.0
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
mrpt::utils::CServerTCPSocket Class Reference

Detailed Description

A TCP socket that can be wait for client connections to enter.

Unless otherwise noticed, operations are blocking.

Definition at line 27 of file CServerTCPSocket.h.

#include <mrpt/utils/CServerTCPSocket.h>

Inheritance diagram for mrpt::utils::CServerTCPSocket:
Inheritance graph

Public Member Functions

 CServerTCPSocket (unsigned short listenPort, const std::string &IPaddress=std::string("127.0.0.1"), int maxConnectionsWaiting=50, bool verbose=false)
 Constructor that creates the socket, performs binding, and start listening mode. More...
 
 ~CServerTCPSocket ()
 Destructor. More...
 
bool isListening ()
 Returns true if the socket was successfully open and it's bound to the desired port. More...
 
CClientTCPSocketaccept (int timeout_ms=-1)
 Waits for an incoming connection (indefinitely, or with a given timeout) The returned object represents the new connection, and MUST BE deleted by the user when no longer needed. More...
 

Static Public Member Functions

static void printf_debug (const char *frmt,...)
 Sends a formated text to "debugOut" if not NULL, or to cout otherwise. More...
 

Private Member Functions

std::string getLastErrorStr ()
 Returns a description of the last Sockets error. More...
 
void setupSocket (unsigned short listenPort, const std::string &IPaddress, int maxConnectionsWaiting)
 Common code called from the platform-dependant constructor. More...
 

Private Attributes

int m_serverSock
 The handle for the listening server TCP socket. More...
 
bool m_verbose
 

Constructor & Destructor Documentation

◆ CServerTCPSocket()

mrpt::utils::CServerTCPSocket::CServerTCPSocket ( unsigned short  listenPort,
const std::string &  IPaddress = std::string("127.0.0.1"),
int  maxConnectionsWaiting = 50,
bool  verbose = false 
)

Constructor that creates the socket, performs binding, and start listening mode.

Parameters
listenPortThe port to bound to.
IPaddressThe interface to bound the socket to. By default is 127.0.0.1 for localhost, for all network interfaces use 0.0.0.0.
maxConnectionsWaitingMaximum number of incoming connections waiting for "accept" before new ones are rejected.
verboseWhether to dump state information to the output defined in the utils::CDebugOutputCapable interface. You can check if the socket has been created OK with "isListening".
See also
isListening
Exceptions
std::exceptionIf there is any error creating the socket, with a textual description of the error.

◆ ~CServerTCPSocket()

mrpt::utils::CServerTCPSocket::~CServerTCPSocket ( )

Destructor.

Member Function Documentation

◆ accept()

CClientTCPSocket* mrpt::utils::CServerTCPSocket::accept ( int  timeout_ms = -1)

Waits for an incoming connection (indefinitely, or with a given timeout) The returned object represents the new connection, and MUST BE deleted by the user when no longer needed.

Parameters
timeout_msThe timeout for the waiting, in milliseconds. Set this to "-1" to disable timeout (i.e. timeout=infinite)
Returns
The incoming connection, or NULL on timeout or error.

◆ getLastErrorStr()

std::string mrpt::utils::CServerTCPSocket::getLastErrorStr ( )
inlineprivate

Returns a description of the last Sockets error.

Definition at line 42 of file CServerTCPSocket.h.

References mrpt::utils::net::getLastSocketErrorStr().

◆ isListening()

bool mrpt::utils::CServerTCPSocket::isListening ( )

Returns true if the socket was successfully open and it's bound to the desired port.

◆ printf_debug()

static void mrpt::utils::CDebugOutputCapable::printf_debug ( const char *  frmt,
  ... 
)
staticinherited

Sends a formated text to "debugOut" if not NULL, or to cout otherwise.

Referenced by mrpt::math::CLevenbergMarquardtTempl< VECTORTYPE, USERPARAM >::execute().

◆ setupSocket()

void mrpt::utils::CServerTCPSocket::setupSocket ( unsigned short  listenPort,
const std::string &  IPaddress,
int  maxConnectionsWaiting 
)
private

Common code called from the platform-dependant constructor.

Member Data Documentation

◆ m_serverSock

int mrpt::utils::CServerTCPSocket::m_serverSock
private

The handle for the listening server TCP socket.

Definition at line 38 of file CServerTCPSocket.h.

◆ m_verbose

bool mrpt::utils::CServerTCPSocket::m_verbose
private

Definition at line 44 of file CServerTCPSocket.h.




Page generated by Doxygen 1.9.1 for MRPT 1.4.0 SVN: at Fri Sep 3 01:11:30 UTC 2021