Main MRPT website > C++ reference for MRPT 1.5.7
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-2017, 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  */
27  class BASE_IMPEXP CServerTCPSocket : public utils::COutputLogger
28  {
29  public:
30  /** Constructor that creates the socket, performs binding, and start listening mode.
31  * \param listenPort The port to bound to.
32  * \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.
33  * \param maxConnectionsWaiting Maximum number of incoming connections waiting for "accept" before new ones are rejected.
34  * You can check if the socket has been created OK with "isListening".
35  * \sa isListening
36  * \exception std::exception If there is any error creating the socket, with a textual description of the error.
37  */
39  unsigned short listenPort,
40  const std::string &IPaddress = std::string("127.0.0.1"),
41  int maxConnectionsWaiting = 50,
42  mrpt::utils::VerbosityLevel verbosityLevel = mrpt::utils::LVL_INFO
43  );
44  virtual ~CServerTCPSocket( ); //!< Dtor
45 
46  bool isListening(); //!< Returns true if the socket was successfully open and it's bound to the desired port.
47 
48  /** Waits for an incoming connection (indefinitely, or with a given timeout)
49  * The returned object represents the new connection, and MUST BE deleted by the user when no longer needed.
50  * \param timeout_ms The timeout for the waiting, in milliseconds. Set this to "-1" to disable timeout (i.e. timeout=infinite)
51  * \return The incoming connection, or NULL on timeout or error.
52  */
53  CClientTCPSocket * accept( int timeout_ms = -1 );
54 
55  private:
56  /** The handle for the listening server TCP socket. */
57 #ifdef MRPT_OS_WINDOWS
58  unsigned int
59 #else
60  int
61 #endif
63 
64  /** Returns a description of the last Sockets error */
66 
67  /** Common code called from the platform-dependant constructor */
68  void setupSocket(
69  unsigned short listenPort,
70  const std::string &IPaddress,
71  int maxConnectionsWaiting );
72 
73  }; // End of class def.
74 
75 } // End of namespace
76 } // End of namespace
77 
78 #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.
std::string BASE_IMPEXP getLastSocketErrorStr()
Returns a description of the last Sockets error.
Definition: net_utils.cpp:519
std::string getLastErrorStr()
Returns a description of the last Sockets error.
GLsizei const GLchar ** string
Definition: glext.h:3919
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...



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019