Main MRPT website > C++ reference for MRPT 1.9.9
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-2018, 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 #pragma once
10 
11 #include <mrpt/core/common.h>
13 #include <string>
14 #include <memory> // unique_ptr
15 
16 namespace mrpt
17 {
18 namespace comms
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 mrpt_comms_grp
25  */
27 {
28  public:
29  /** Constructor that creates the socket, performs binding, and start
30  * listening mode.
31  * \param listenPort The port to bound to.
32  * \param IPaddress The interface to bound the socket to. By default is
33  * 127.0.0.1 for localhost, for all network interfaces use 0.0.0.0.
34  * \param maxConnectionsWaiting Maximum number of incoming connections
35  * waiting for "accept" before new ones are rejected.
36  * You can check if the socket has been created OK with "isListening".
37  * \sa isListening
38  * \exception std::exception If there is any error creating the socket,
39  * with a textual description of the error.
40  */
42  unsigned short listenPort,
43  const std::string& IPaddress = std::string("127.0.0.1"),
44  int maxConnectionsWaiting = 50,
46  /** Dtor */
47  virtual ~CServerTCPSocket();
48 
49  /** Returns true if the socket was successfully open and it's bound to the
50  * desired port. */
51  bool isListening();
52 
53  /** Waits for an incoming connection (indefinitely, or with a given timeout)
54  * The returned object represents the new connection, and MUST BE deleted
55  * by the user when no longer needed.
56  * \param timeout_ms The timeout for the waiting, in milliseconds. Set this
57  * to "-1" to disable timeout (i.e. timeout=infinite)
58  * \return The incoming connection, or nullptr on timeout or error.
59  */
60  std::unique_ptr<CClientTCPSocket> accept(int timeout_ms = -1);
61 
62  private:
63 /** The handle for the listening server TCP socket. */
64 #ifdef _WIN32
65  unsigned int
66 #else
67  int
68 #endif
70 
71  /** Returns a description of the last Sockets error */
73 
74  /** Common code called from the platform-dependant constructor */
75  void setupSocket(
76  unsigned short listenPort, const std::string& IPaddress,
77  int maxConnectionsWaiting);
78 
79 }; // End of class def.
80 
81 } // End of namespace
82 } // End of namespace
mrpt::comms::CServerTCPSocket
A TCP socket that can be wait for client connections to enter.
Definition: CServerTCPSocket.h:26
mrpt::comms::CServerTCPSocket::setupSocket
void setupSocket(unsigned short listenPort, const std::string &IPaddress, int maxConnectionsWaiting)
Common code called from the platform-dependant constructor.
Definition: CServerTCPSocket_common.cpp:44
mrpt::comms::CServerTCPSocket::isListening
bool isListening()
Returns true if the socket was successfully open and it's bound to the desired port.
Definition: CServerTCPSocket_common.cpp:83
mrpt::comms::CServerTCPSocket::CServerTCPSocket
CServerTCPSocket(unsigned short listenPort, const std::string &IPaddress=std::string("127.0.0.1"), int maxConnectionsWaiting=50, mrpt::system::VerbosityLevel verbosityLevel=mrpt::system::LVL_INFO)
Constructor that creates the socket, performs binding, and start listening mode.
Definition: CServerTCPSocket.cpp:41
mrpt::comms::CServerTCPSocket::accept
std::unique_ptr< CClientTCPSocket > accept(int timeout_ms=-1)
Waits for an incoming connection (indefinitely, or with a given timeout) The returned object represen...
Definition: CServerTCPSocket_common.cpp:87
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::system::LVL_INFO
@ LVL_INFO
Definition: system/COutputLogger.h:31
mrpt::comms::CServerTCPSocket::m_serverSock
unsigned int m_serverSock
The handle for the listening server TCP socket.
Definition: CServerTCPSocket.h:69
mrpt::comms::CServerTCPSocket::~CServerTCPSocket
virtual ~CServerTCPSocket()
Dtor.
Definition: CServerTCPSocket.cpp:65
mrpt::system::VerbosityLevel
VerbosityLevel
Enumeration of available verbosity levels.
Definition: system/COutputLogger.h:28
COutputLogger.h
comms
Definition: CInterfaceFTDI_WIN.cpp:19
mrpt::comms::CServerTCPSocket::getLastErrorStr
std::string getLastErrorStr()
Returns a description of the last Sockets error.
Definition: CServerTCPSocket_common.cpp:39
mrpt::system::COutputLogger
Versatile class for consistent logging and management of output messages.
Definition: system/COutputLogger.h:117
common.h
string
GLsizei const GLchar ** string
Definition: glext.h:4101



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST