Main MRPT website > C++ reference for 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 }
CClientTCPSocket.h
exceptions.h
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::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::system::COutputLogger::setVerbosityLevel
void setVerbosityLevel(const VerbosityLevel level)
alias of setMinLoggingLevel()
Definition: COutputLogger.cpp:138
CServerTCPSocket.h
mrpt::comms
Serial and networking devices and utilities.
Definition: CClientTCPSocket.h:21
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::utils::COutputLogger
mrpt::system::COutputLogger COutputLogger
Definition: utils/COutputLogger.h:7
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
mrpt::comms::CServerTCPSocket::m_serverSock
unsigned int m_serverSock
The handle for the listening server TCP socket.
Definition: CServerTCPSocket.h:69
MRPT_TRY_END
#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
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
MRPT_TRY_START
#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
mrpt::comms::CServerTCPSocket::getLastErrorStr
std::string getLastErrorStr()
Returns a description of the last Sockets error.
Definition: CServerTCPSocket_common.cpp:39
string
GLsizei const GLchar ** string
Definition: glext.h:4101
comms-precomp.h



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