coral
A C++ library for distributed co-simulation
|
A class for sending and receiving UDP broadcast messages. More...
#include "coral/net/udp.hpp"
Public Types | |
typedef int | NativeSocket |
The native socket handle type (SOCKET on Windows, int on *NIX). | |
Public Member Functions | |
BroadcastSocket (const ip::Address &networkInterface, ip::Port port, int flags=0) | |
Constructor. More... | |
~BroadcastSocket () CORAL_NOEXCEPT | |
Destructor. | |
BroadcastSocket (BroadcastSocket &&) CORAL_NOEXCEPT | |
Move constructor. | |
BroadcastSocket & | operator= (BroadcastSocket &&) CORAL_NOEXCEPT |
Move assignment operator. | |
void | Send (const char *buffer, std::size_t msgSize) |
Broadcasts a message. More... | |
std::size_t | Receive (char *buffer, std::size_t bufferSize, ip::Address *sender) |
Receives a message. More... | |
NativeSocket | NativeHandle () const CORAL_NOEXCEPT |
The native socket handle. | |
A class for sending and receiving UDP broadcast messages.
Flags that control the operation of this class.
Enumerator | |
---|---|
onlySend |
Only send, don't receive (i.e., don't bind the socket). If this flag is set, Receive() won't work and shouldn't be called. |
coral::net::udp::BroadcastSocket::BroadcastSocket | ( | const ip::Address & | networkInterface, |
ip::Port | port, | ||
int | flags = 0 |
||
) |
Constructor.
[in] | networkInterface | The name or IP address of the network interface to broadcast and listen on. The special value "*" means "all interfaces". |
[in] | port | The port to broadcast and listen on. |
[in] | flags | A bitwise OR of one or more Flags values, or zero to use defaults. |
std::runtime_error | on failure. |
std::size_t coral::net::udp::BroadcastSocket::Receive | ( | char * | buffer, |
std::size_t | bufferSize, | ||
ip::Address * | sender | ||
) |
Receives a message.
[in] | buffer | A pointer to an array of size at least bufferSize bytes, to which the message data will be written. |
[in] | bufferSize | The size of the supplied buffer. |
[in] | sender | If nonnull, the object pointed to by this parameter will be filled with the IP address of the message sender. |
bufferSize
, meaning that the message has been truncated.std::runtime_error | on failure. |
void coral::net::udp::BroadcastSocket::Send | ( | const char * | buffer, |
std::size_t | msgSize | ||
) |
Broadcasts a message.
[in] | buffer | A buffer of size at least msgSize , which contains the message data. |
[in] | msgSize | The size of the message. |
std::runtime_error | on failure. |