Main MRPT website > C++ reference for MRPT 1.5.7
CServerTCPSocket_WIN.cpp
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 
10 #include "base-precomp.h" // Precompiled headers
11 
12 
13 #include <MRPT/config.h>
14 
15 #ifdef MRPT_OS_WINDOWS
16 
17 #include <winsock.h>
18 #if (__BORLANDC__) || (_MSC_VER)
19 # pragma comment (lib,"WS2_32.LIB")
20 #endif
21 
24 #include <mrpt/system/os.h>
25 
26 using namespace mrpt::utils;
27 
28 /*---------------------------------------------------------------
29  Constructor
30  ---------------------------------------------------------------*/
32  unsigned short listenPort,
33  const std::string &IPaddress,
34  int maxConnectionsWaiting,
35  mrpt::utils::VerbosityLevel verbosityLevel
36  ) :
37  COutputLogger("CServerTCPSocket")
38 {
40  setVerbosityLevel(verbosityLevel);
41 
42  // Init the WinSock Library:
43  // ----------------------------
44  WORD wVersionRequested;
45  WSADATA wsaData;
46 
47  wVersionRequested = MAKEWORD( 2, 0 );
48 
49  if ( 0 != WSAStartup( wVersionRequested, &wsaData ) )
51 
52  // Create the socket and put it listening:
53  setupSocket( listenPort, IPaddress, maxConnectionsWaiting );
54 
55  MRPT_END
56 }
57 
58 /*---------------------------------------------------------------
59  Destructor
60  ---------------------------------------------------------------*/
62 {
63  // Delete socket:
65  closesocket( m_serverSock );
66 
67  WSACleanup();
68 }
69 
70 
71 #endif // MRPT_OS_WINDOWS
#define INVALID_SOCKET
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
#define THROW_EXCEPTION(msg)
void setupSocket(unsigned short listenPort, const std::string &IPaddress, int maxConnectionsWaiting)
Common code called from the platform-dependant constructor.
CServerTCPSocket(unsigned short listenPort, const std::string &IPaddress=std::string("127.0.0.1"), int maxConnectionsWaiting=50, mrpt::utils::VerbosityLevel verbosityLevel=mrpt::utils::LVL_INFO)
Constructor that creates the socket, performs binding, and start listening mode.
virtual ~CServerTCPSocket()
Dtor.
int m_serverSock
The handle for the listening server TCP socket.
#define MRPT_END
std::string getLastErrorStr()
Returns a description of the last Sockets error.
GLsizei const GLchar ** string
Definition: glext.h:3919
#define MRPT_START



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