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



Page generated by Doxygen 1.8.12 for MRPT 1.3.2 SVN: at Mon Oct 3 19:22:36 UTC 2016