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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019