Main MRPT website
>
C++ reference
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
mrpt
utils
CServerTCPSocket.h
Go to the documentation of this file.
1
/* +---------------------------------------------------------------------------+
2
| The Mobile Robot Programming Toolkit (MRPT) C++ library |
3
| |
4
| http://www.mrpt.org/ |
5
| |
6
| Copyright (C) 2005-2012 University of Malaga |
7
| |
8
| This software was written by the Machine Perception and Intelligent |
9
| Robotics Lab, University of Malaga (Spain). |
10
| Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11
| |
12
| This file is part of the MRPT project. |
13
| |
14
| MRPT is free software: you can redistribute it and/or modify |
15
| it under the terms of the GNU General Public License as published by |
16
| the Free Software Foundation, either version 3 of the License, or |
17
| (at your option) any later version. |
18
| |
19
| MRPT is distributed in the hope that it will be useful, |
20
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
| GNU General Public License for more details. |
23
| |
24
| You should have received a copy of the GNU General Public License |
25
| along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26
| |
27
+---------------------------------------------------------------------------+ */
28
#ifndef CServerTCPSocket_H
29
#define CServerTCPSocket_H
30
31
#include <mrpt/config.h>
32
#include <
mrpt/utils/utils_defs.h
>
33
#include <
mrpt/utils/CStream.h
>
34
35
#include <
mrpt/utils/CDebugOutputCapable.h
>
36
37
namespace
mrpt
38
{
39
namespace
utils
40
{
41
class
CClientTCPSocket;
42
43
/** A TCP socket that can be wait for client connections to enter.
44
* Unless otherwise noticed, operations are blocking.
45
* \ingroup network_grp
46
*/
47
class
BASE_IMPEXP
CServerTCPSocket
:
public
utils::CDebugOutputCapable
48
{
49
private
:
50
51
#ifdef MRPT_OS_WINDOWS
52
/** The handle for the listening server TCP socket.
53
*/
54
unsigned
int
m_serverSock;
55
#else
56
/** The handle for the listening server TCP socket.
57
*/
58
int
m_serverSock
;
59
#endif
60
61
/** Returns a description of the last error */
62
std::string getLastErrorStr();
63
64
bool
m_verbose
;
65
66
/** Common code called from the platform-dependant constructor */
67
void
setupSocket(
68
unsigned
short
listenPort,
69
const
std::string &IPaddress,
70
int
maxConnectionsWaiting );
71
72
public
:
73
/** Constructor that creates the socket, performs binding, and start listening mode.
74
* \param listenPort The port to bound to.
75
* \param IPaddress The interface to bound the socket to. By default 127.0.0.1 implies listening at all network interfaces.
76
* \param maxConnectionsWaiting Maximum number of incoming connections waiting for "accept" before new ones are rejected.
77
* \param verbose Whether to dump state information to the output defined in the utils::CDebugOutputCapable interface.
78
* You can check if the socket has been created OK with "isListening".
79
* \sa isListening
80
* \exception std::exception If there is any error creating the socket, with a textual description of the error.
81
*/
82
CServerTCPSocket
(
83
unsigned
short
listenPort,
84
const
std::string &IPaddress = std::string(
"127.0.0.1"
),
85
int
maxConnectionsWaiting = 50,
86
bool
verbose =
false
87
);
88
89
/** Destructor
90
*/
91
~
CServerTCPSocket
( );
92
93
/** Returns true if the socket was successfully open and it's bound to the desired port.
94
*/
95
bool
isListening();
96
97
/** Waits for an incoming connection (indefinitely, or with a given timeout)
98
* The returned object represents the new connection, and MUST BE deleted by the user when no longer needed.
99
* \param timeout_ms The timeout for the waiting, in milliseconds. Set this to "-1" to disable timeout (i.e. timeout=infinite)
100
* \return The incoming connection, or NULL on timeout or error.
101
*/
102
CClientTCPSocket
* accept(
int
timeout_ms = -1 );
103
104
105
106
};
// End of class def.
107
108
}
// End of namespace
109
}
// End of namespace
110
111
#endif // file
Page generated by
Doxygen 1.8.3
for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013