TcpSocket.h
Go to the documentation of this file.
1 // -- BEGIN LICENSE BLOCK ----------------------------------------------
20 // -- END LICENSE BLOCK ------------------------------------------------
21 
22 #pragma once
23 #include <cstdint>
24 #include <string>
25 
26 #include "ITransport.h"
27 
28 // Include socket
29 #ifdef _WIN32 // Windows specific
30 # include <Ws2tcpip.h>
31 # include <winsock2.h>
32 // to use with other compiler than Visual C++ need to set Linker flag -lws2_32
33 # ifdef _MSC_VER
34 # pragma comment(lib, "ws2_32.lib")
35 # endif
36 #else // Linux specific
37 # include <arpa/inet.h>
38 # include <netinet/in.h>
39 # include <sys/socket.h>
40 # include <sys/types.h>
41 # include <unistd.h>
42 
43 typedef int SOCKET;
44 # define INVALID_SOCKET ((SOCKET)(~0))
45 # define SOCKET_ERROR (-1)
46 #endif
47 
48 namespace visionary {
49 
50 class TcpSocket : public ITransport
51 {
52 public:
53  int connect(const std::string& hostname, uint16_t port);
54  int openServer(uint16_t port);
55  int openTcp(uint16_t port);
56  bool WaitForConnection();
57  int shutdown();
58 
59  int send(const std::vector<std::uint8_t>& buffer) override;
60  int recv(std::vector<std::uint8_t>& buffer, std::size_t maxBytesToReceive) override;
61  int read(std::vector<std::uint8_t>& buffer, std::size_t nBytesToReceive) override;
62 
63 private:
67 };
68 
69 } // namespace visionary
visionary
Definition: AuthenticationLegacy.h:25
visionary::TcpSocket::read
int read(std::vector< std::uint8_t > &buffer, std::size_t nBytesToReceive) override
Definition: TcpSocket.cpp:207
visionary::TcpSocket::m_socketServer
SOCKET m_socketServer
Definition: TcpSocket.h:65
SOCKET
int SOCKET
Definition: TcpSocket.h:43
visionary::TcpSocket::m_socketTcp
SOCKET m_socketTcp
Definition: TcpSocket.h:66
visionary::TcpSocket::WaitForConnection
bool WaitForConnection()
Definition: TcpSocket.cpp:154
visionary::TcpSocket::m_socket
SOCKET m_socket
Definition: TcpSocket.h:64
visionary::TcpSocket::openTcp
int openTcp(uint16_t port)
Definition: TcpSocket.cpp:118
visionary::TcpSocket::shutdown
int shutdown()
Definition: TcpSocket.cpp:172
ITransport.h
visionary::ITransport
Definition: ITransport.h:31
visionary::TcpSocket::send
int send(const std::vector< std::uint8_t > &buffer) override
Definition: TcpSocket.cpp:192
visionary::TcpSocket::openServer
int openServer(uint16_t port)
Definition: TcpSocket.cpp:80
visionary::TcpSocket::connect
int connect(const std::string &hostname, uint16_t port)
Definition: TcpSocket.cpp:26
visionary::TcpSocket
Definition: TcpSocket.h:50
visionary::TcpSocket::recv
int recv(std::vector< std::uint8_t > &buffer, std::size_t maxBytesToReceive) override
Definition: TcpSocket.cpp:198


sick_safevisionary_base
Author(s):
autogenerated on Sat Oct 21 2023 02:24:26