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 
12 #include <mrpt/utils/core_defs.h>
14 #include <mrpt/utils/net_utils.h>
15 #include <string>
16 
17 namespace mrpt
18 {
19 namespace 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 
44  bool m_verbose;
45 
46  /** Common code called from the platform-dependant constructor */
47  void setupSocket(
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  */
71  ~CServerTCPSocket( );
72 
73  /** Returns true if the socket was successfully open and it's bound to the desired port.
74  */
75  bool isListening();
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
mrpt::utils::CServerTCPSocket
A TCP socket that can be wait for client connections to enter.
Definition: CServerTCPSocket.h:27
mrpt::utils::CDebugOutputCapable
This base class provides a common printf-like method to send debug information to std::cout,...
Definition: CDebugOutputCapable.h:31
mrpt::utils::net::getLastSocketErrorStr
std::string BASE_IMPEXP getLastSocketErrorStr()
Returns a description of the last Sockets error.
CDebugOutputCapable.h
mrpt::utils::CClientTCPSocket
A TCP socket that can be connected to a TCP server, implementing MRPT's CStream interface for passing...
Definition: CClientTCPSocket.h:34
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CParticleFilter.h:16
core_defs.h
mrpt::utils::CServerTCPSocket::getLastErrorStr
std::string getLastErrorStr()
Returns a description of the last Sockets error.
Definition: CServerTCPSocket.h:42
mrpt::utils::CServerTCPSocket::m_serverSock
int m_serverSock
The handle for the listening server TCP socket.
Definition: CServerTCPSocket.h:38
net_utils.h
mrpt::utils::CServerTCPSocket::m_verbose
bool m_verbose
Definition: CServerTCPSocket.h:44



Page generated by Doxygen 1.8.17 for MRPT 1.4.0 SVN: at Sat Jan 18 22:37:07 UTC 2020