Main MRPT website > C++ reference for MRPT 1.4.0
CServerTCPSocket.h
Go to the documentation of this file.
1/* +---------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | http://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6 | See: http://www.mrpt.org/Authors - All rights reserved. |
7 | Released under BSD License. See details in http://www.mrpt.org/License |
8 +---------------------------------------------------------------------------+ */
9#ifndef CServerTCPSocket_H
10#define CServerTCPSocket_H
11
15#include <string>
16
17namespace mrpt
18{
19namespace utils
20{
21 class CClientTCPSocket;
22
23 /** A TCP socket that can be wait for client connections to enter.
24 * Unless otherwise noticed, operations are blocking.
25 * \ingroup network_grp
26 */
28 {
29 private:
30
31#ifdef MRPT_OS_WINDOWS
32 /** The handle for the listening server TCP socket.
33 */
34 unsigned int m_serverSock;
35#else
36 /** The handle for the listening server TCP socket.
37 */
39#endif
40
41 /** Returns a description of the last Sockets error */
43
45
46 /** Common code called from the platform-dependant constructor */
48 unsigned short listenPort,
49 const std::string &IPaddress,
50 int maxConnectionsWaiting );
51
52 public:
53 /** Constructor that creates the socket, performs binding, and start listening mode.
54 * \param listenPort The port to bound to.
55 * \param 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.
56 * \param maxConnectionsWaiting Maximum number of incoming connections waiting for "accept" before new ones are rejected.
57 * \param verbose Whether to dump state information to the output defined in the utils::CDebugOutputCapable interface.
58 * You can check if the socket has been created OK with "isListening".
59 * \sa isListening
60 * \exception std::exception If there is any error creating the socket, with a textual description of the error.
61 */
63 unsigned short listenPort,
64 const std::string &IPaddress = std::string("127.0.0.1"),
65 int maxConnectionsWaiting = 50,
66 bool verbose = false
67 );
68
69 /** Destructor
70 */
72
73 /** Returns true if the socket was successfully open and it's bound to the desired port.
74 */
76
77 /** Waits for an incoming connection (indefinitely, or with a given timeout)
78 * The returned object represents the new connection, and MUST BE deleted by the user when no longer needed.
79 * \param timeout_ms The timeout for the waiting, in milliseconds. Set this to "-1" to disable timeout (i.e. timeout=infinite)
80 * \return The incoming connection, or NULL on timeout or error.
81 */
82 CClientTCPSocket * accept( int timeout_ms = -1 );
83
84
85
86 }; // End of class def.
87
88} // End of namespace
89} // End of namespace
90
91#endif // file
A TCP socket that can be connected to a TCP server, implementing MRPT's CStream interface for passing...
This base class provides a common printf-like method to send debug information to std::cout,...
A TCP socket that can be wait for client connections to enter.
std::string getLastErrorStr()
Returns a description of the last Sockets error.
void setupSocket(unsigned short listenPort, const std::string &IPaddress, int maxConnectionsWaiting)
Common code called from the platform-dependant constructor.
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.
bool isListening()
Returns true if the socket was successfully open and it's bound to the desired port.
int m_serverSock
The handle for the listening server TCP socket.
CClientTCPSocket * accept(int timeout_ms=-1)
Waits for an incoming connection (indefinitely, or with a given timeout) The returned object represen...
std::string BASE_IMPEXP getLastSocketErrorStr()
Returns a description of the last Sockets error.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Tue Jan 17 22:27:43 UTC 2023