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>
Public Member Functions | |
CServerTCPSocket (unsigned short listenPort, const std::string &IPaddress=std::string("127.0.0.1"), int maxConnectionsWaiting=50, mrpt::utils::VerbosityLevel verbosityLevel=mrpt::utils::LVL_INFO) | |
Constructor that creates the socket, performs binding, and start listening mode. More... | |
virtual | ~CServerTCPSocket () |
Dtor. More... | |
bool | isListening () |
Returns true if the socket was successfully open and it's bound to the desired port. More... | |
CClientTCPSocket * | 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. 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... | |
mrpt::utils::CServerTCPSocket::CServerTCPSocket | ( | unsigned short | listenPort, |
const std::string & | IPaddress = std::string("127.0.0.1") , |
||
int | maxConnectionsWaiting = 50 , |
||
mrpt::utils::VerbosityLevel | verbosityLevel = mrpt::utils::LVL_INFO |
||
) |
Constructor that creates the socket, performs binding, and start listening mode.
listenPort | The port to bound to. |
IPaddress | The interface to bound the socket to. By default is 127.0.0.1 for localhost, for all network interfaces use 0.0.0.0. |
maxConnectionsWaiting | Maximum number of incoming connections waiting for "accept" before new ones are rejected. You can check if the socket has been created OK with "isListening". |
std::exception | If there is any error creating the socket, with a textual description of the error. |
|
virtual |
Dtor.
CClientTCPSocket * 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.
timeout_ms | The timeout for the waiting, in milliseconds. Set this to "-1" to disable timeout (i.e. timeout=infinite) |
Definition at line 89 of file CServerTCPSocket_common.cpp.
References mrpt::format(), mrpt::system::os::fprintf(), getLastErrorStr(), INVALID_SOCKET, mrpt::utils::CClientTCPSocket::m_hSock, mrpt::utils::CClientTCPSocket::m_remotePartIP, mrpt::utils::CClientTCPSocket::m_remotePartPort, m_serverSock, MRPT_END, MRPT_LOG_DEBUG, MRPT_LOG_WARN, and MRPT_START.
|
inlineprivate |
Returns a description of the last Sockets error.
Definition at line 65 of file CServerTCPSocket.h.
References mrpt::utils::net::getLastSocketErrorStr().
Referenced by accept(), and setupSocket().
bool CServerTCPSocket::isListening | ( | ) |
Returns true if the socket was successfully open and it's bound to the desired port.
Definition at line 81 of file CServerTCPSocket_common.cpp.
References INVALID_SOCKET, and m_serverSock.
|
private |
Common code called from the platform-dependant constructor.
Definition at line 42 of file CServerTCPSocket_common.cpp.
References mrpt::format(), getLastErrorStr(), INVALID_SOCKET, m_serverSock, MRPT_END, MRPT_LOG_DEBUG, MRPT_START, and THROW_EXCEPTION.
|
private |
The handle for the listening server TCP socket.
Definition at line 62 of file CServerTCPSocket.h.
Referenced by accept(), isListening(), and setupSocket().
Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020 |