UdpSocket.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 UdpSocket : public ITransport
51 {
52 public:
53  UdpSocket();
54 
55  int connect(const std::string& hostname, uint16_t port);
56  int bindPort(std::uint16_t port);
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:
65  struct sockaddr_in m_udpAddr;
66 
67  int initSocket();
68 };
69 
70 } // namespace visionary
visionary::UdpSocket::read
int read(std::vector< std::uint8_t > &buffer, std::size_t nBytesToReceive) override
Definition: UdpSocket.cpp:157
SOCKET
int SOCKET
Definition: UdpSocket.h:43
visionary::UdpSocket::send
int send(const std::vector< std::uint8_t > &buffer) override
Definition: UdpSocket.cpp:137
visionary
Definition: AuthenticationLegacy.h:25
SOCKET
int SOCKET
Definition: TcpSocket.h:43
visionary::UdpSocket::recv
int recv(std::vector< std::uint8_t > &buffer, std::size_t maxBytesToReceive) override
Definition: UdpSocket.cpp:148
visionary::UdpSocket::UdpSocket
UdpSocket()
Definition: UdpSocket.cpp:28
visionary::UdpSocket::bindPort
int bindPort(std::uint16_t port)
Definition: UdpSocket.cpp:97
visionary::UdpSocket
Definition: UdpSocket.h:50
visionary::UdpSocket::m_socket
SOCKET m_socket
Definition: UdpSocket.h:64
visionary::UdpSocket::shutdown
int shutdown()
Definition: UdpSocket.cpp:124
visionary::UdpSocket::m_udpAddr
struct sockaddr_in m_udpAddr
Definition: UdpSocket.h:65
visionary::UdpSocket::initSocket
int initSocket()
Definition: UdpSocket.cpp:34
ITransport.h
visionary::ITransport
Definition: ITransport.h:31
visionary::UdpSocket::connect
int connect(const std::string &hostname, uint16_t port)
Definition: UdpSocket.cpp:75


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