7#include "./network_socket.h"
9namespace AsyncBsdSocketLib
15 std::string mNicIpAddress;
16 std::string mMulticastIpAddress;
35 std::string ipAddress,
37 std::string nicIpAddress,
38 std::string multicastIpAddress,
39 bool shareAddress =
true);
51 template <std::
size_t N>
53 const std::array<uint8_t, N> &buffer,
54 std::
string ipAddress,
55 uint16_t port) const noexcept
60 struct sockaddr_in _destinationAddress;
61 _destinationAddress.sin_addr.s_addr = inet_addr(ipAddress.c_str());
62 _destinationAddress.sin_family = AF_INET;
63 _destinationAddress.sin_port = htons(port);
71 (
struct sockaddr *)&_destinationAddress,
72 sizeof(_destinationAddress));
84 template <std::
size_t N>
86 std::array<uint8_t, N> &buffer,
87 std::string &ipAddress,
88 uint16_t &port)
const noexcept
93 struct sockaddr_in _sourceAddress;
94 socklen_t _sourceAddressLength =
sizeof(_sourceAddress);
102 (
struct sockaddr *)&_sourceAddress,
103 &_sourceAddressLength);
106 char _ipAddress[INET_ADDRSTRLEN];
107 inet_ntop(AF_INET, &(_sourceAddress.sin_addr), _ipAddress, INET_ADDRSTRLEN);
108 ipAddress = std::string(_ipAddress);
111 port = htons(_sourceAddress.sin_port);
int FileDescriptor
File descriptor.
Definition: communicator.h:13
TCP/IP network socket.
Definition: network_socket.h:13
UDP client which can play both client and listener roles.
Definition: udp_client.h:13
ssize_t Send(const std::array< uint8_t, N > &buffer, std::string ipAddress, uint16_t port) const noexcept
Send a byte array to a destination.
Definition: udp_client.h:52
int Connection() const noexcept override
Connection descriptor for sending and receiving.
UdpClient(std::string ipAddress, uint16_t port)
Unicast UDP socket constructor.
bool TrySetup() noexcept override
Try to setup the communicator.
UdpClient(std::string ipAddress, uint16_t port, std::string nicIpAddress, std::string multicastIpAddress, bool shareAddress=true)
Multicast UDP socket constructor.
ssize_t Receive(std::array< uint8_t, N > &buffer, std::string &ipAddress, uint16_t &port) const noexcept
Receive a byte array from a source.
Definition: udp_client.h:85