MRPT  1.9.9
CServerTCPSocket.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-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 
10 #include "comms-precomp.h" // Precompiled headers
11 
14 #include <mrpt/core/exceptions.h>
15 
16 #ifdef _WIN32
17 // Windows
18 #include <winsock.h>
19 #if defined(_MSC_VER)
20 #pragma comment(lib, "WS2_32.LIB")
21 #endif
22 #else
23 // Linux & Apple
24 // Platform specific headers:
25 #include <sys/socket.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28 #include <errno.h>
29 //#include <iostream>
30 #include <sys/types.h>
31 #include <sys/ioctl.h>
32 #include <netdb.h>
33 #include <arpa/inet.h>
34 #include <netinet/in.h>
35 #include <sys/socket.h>
36 #endif
37 
38 using namespace mrpt;
39 using namespace mrpt::comms;
40 
42  unsigned short listenPort, const std::string& IPaddress,
43  int maxConnectionsWaiting, mrpt::system::VerbosityLevel verbosityLevel)
44  : COutputLogger("CServerTCPSocket")
45 {
47  setVerbosityLevel(verbosityLevel);
48 
49 #if defined(_WIN32)
50  // Init the WinSock Library:
51  // ----------------------------
52  WORD wVersionRequested;
53  WSADATA wsaData;
54 
55  wVersionRequested = MAKEWORD(2, 0);
56 
57  if (0 != WSAStartup(wVersionRequested, &wsaData))
59 #endif
60 
61  setupSocket(listenPort, IPaddress, maxConnectionsWaiting);
63 }
64 
66 {
67 // Delete socket:
68 #if defined(_WIN32)
69  if (m_serverSock != INVALID_SOCKET) closesocket(m_serverSock);
70  WSACleanup();
71 #else
72  if (m_serverSock != -1) close(m_serverSock);
73 #endif
74 }
#define MRPT_TRY_END
The end of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an ex...
Definition: exceptions.h:231
VerbosityLevel
Enumeration of available verbosity levels.
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
std::string getLastErrorStr()
Returns a description of the last Sockets error.
mrpt::system::COutputLogger COutputLogger
unsigned int m_serverSock
The handle for the listening server TCP socket.
#define MRPT_TRY_START
The start of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an ...
Definition: exceptions.h:224
void setupSocket(unsigned short listenPort, const std::string &IPaddress, int maxConnectionsWaiting)
Common code called from the platform-dependant constructor.
GLsizei const GLchar ** string
Definition: glext.h:4101
void setVerbosityLevel(const VerbosityLevel level)
alias of setMinLoggingLevel()
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Serial and networking devices and utilities.
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.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020