coral
A C++ library for distributed co-simulation
Public Types | Public Member Functions | List of all members
coral::net::udp::BroadcastSocket Class Reference

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.
 
BroadcastSocketoperator= (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.
 

Detailed Description

A class for sending and receiving UDP broadcast messages.

Member Enumeration Documentation

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.

Constructor & Destructor Documentation

coral::net::udp::BroadcastSocket::BroadcastSocket ( const ip::Address networkInterface,
ip::Port  port,
int  flags = 0 
)

Constructor.

Parameters
[in]networkInterfaceThe name or IP address of the network interface to broadcast and listen on. The special value "*" means "all interfaces".
[in]portThe port to broadcast and listen on.
[in]flagsA bitwise OR of one or more Flags values, or zero to use defaults.
Exceptions
std::runtime_erroron failure.

Member Function Documentation

std::size_t coral::net::udp::BroadcastSocket::Receive ( char *  buffer,
std::size_t  bufferSize,
ip::Address sender 
)

Receives a message.

Parameters
[in]bufferA pointer to an array of size at least bufferSize bytes, to which the message data will be written.
[in]bufferSizeThe size of the supplied buffer.
[in]senderIf nonnull, the object pointed to by this parameter will be filled with the IP address of the message sender.
Returns
The number of bytes received. This may be more than bufferSize, meaning that the message has been truncated.
Exceptions
std::runtime_erroron failure.
void coral::net::udp::BroadcastSocket::Send ( const char *  buffer,
std::size_t  msgSize 
)

Broadcasts a message.

Parameters
[in]bufferA buffer of size at least msgSize, which contains the message data.
[in]msgSizeThe size of the message.
Exceptions
std::runtime_erroron failure.

The documentation for this class was generated from the following file: