XPMP2
X-Plane multiplayer library 2 - using instancing
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
XPMP2::UDPMulticast Class Reference

UDP Multicast, always binding to INADDR_ANY. More...

#include <Network.h>

+ Inheritance diagram for XPMP2::UDPMulticast:

Public Member Functions

 UDPMulticast ()
 Default constructor is not doing anything. More...
 
 UDPMulticast (const std::string &_multicastAddr, int _port, const std::string &_sendIntf, int _ttl=8, size_t _bufSize=512, unsigned _timeOut_ms=0)
 Constructor creates a socket and binds it to INADDR_ANY and connects to the given multicast address. More...
 
 ~UDPMulticast () override
 makes sure pMCAddr is cleared up More...
 
const std::string & GetMCAddr () const
 Return formatted multicast address, including port. More...
 
void Join (const std::string &_multicastAddr, int _port, const std::string &_sendIntf, int _ttl=8, size_t _bufSize=512, unsigned _timeOut_ms=0)
 Connect to the multicast group. More...
 
uint8_t GetFamily () const
 Protocol family. More...
 
bool IsIPv4 () const
 IPv4? More...
 
bool IsIPv6 () const
 IPv6? More...
 
void SendToDefault ()
 Send future datagrams on default interfaces only (default) More...
 
void SendToAll ()
 Send future datagrams on all interfaces. More...
 
void SendToIntf (uint32_t idx)
 Send future datagrams on this particular interface only. More...
 
size_t SendMC (const void *_bufSend, size_t _bufSendSize)
 Send a multicast. More...
 
size_t RecvMC (bool bSwitchToRecvIntf, std::string *_pFromAddr=nullptr, SockAddrTy *_pFromSockAddr=nullptr, bool *_pbIntfChanged=nullptr)
 Receive a multicast, received message is in XPMP2::SocketNetworking::GetBuf() More...
 
- Public Member Functions inherited from XPMP2::SocketNetworking
 SocketNetworking ()
 Default constructor is not doing anything. More...
 
virtual ~SocketNetworking ()
 Destructor makes sure the socket is closed. More...
 
virtual void Open (const std::string &_addr, int _port, size_t _bufSize=512, unsigned _timeOut_ms=0, bool _bBroadcast=false)
 Creates a socket and binds it to the given local address. More...
 
virtual void Connect (const std::string &_addr, int _port, size_t _bufSize, unsigned _timeOut_ms=0)
 Creates a socket and connects it to the given remote server. More...
 
virtual void Close ()
 Thread-safely close the connection(s) and frees the buffer. More...
 
bool isOpen () const
 Is a socket open? More...
 
void SetBufSize (size_t _bufSize)
 (Re)Sets the buffer size (or clears it if _bufSize==0) More...
 
SOCKET getSocket () const
 the socket More...
 
int getPort () const
 the port More...
 
std::string getAddr () const
 the interface address More...
 
const char * getBuf () const
 return the buffer More...
 
void setBlocking (bool bBlock)
 Set blocking mode. More...
 
long recv (std::string *_pFromAddr=nullptr, SockAddrTy *_pFromSockAddr=nullptr)
 Waits to receive a message, ensures zero-termination in the buffer. More...
 
long timedRecv (int max_wait_ms, std::string *_pFromAddr=nullptr, SockAddrTy *_pFromSockAddr=nullptr)
 Waits to receive a message with timeout, ensures zero-termination in the buffer. More...
 
virtual bool send (const char *msg)
 send messages on session connection More...
 
bool broadcast (const char *msg)
 Sends a broadcast message. More...
 

Protected Member Functions

void Cleanup ()
 
void GetAddrHints (struct addrinfo &hints) override
 returns information from *pMCAddr More...
 
void SetSendInterface (const in_addr &addr)
 Set multicast send interface (IPv4 only) More...
 
void SetSendInterface (uint32_t ifIdx)
 Set multicast send interface. More...
 

Protected Attributes

std::string multicastAddr
 the multicast address More...
 
struct addrinfo * pMCAddr = nullptr
 the multicast address More...
 
bool bSendToAll = true
 Send out multicast datagrams to all interfaces. More...
 
uint32_t oneIntfIdx = 0
 When sending to one interface only, which one? More...
 
std::map< SockAddrTy, std::chrono::time_point< std::chrono::steady_clock > > mapSender
 Keep a list of sources we received data from to be able to identify new sources. More...
 
- Protected Attributes inherited from XPMP2::SocketNetworking
SOCKET f_socket = INVALID_SOCKET
 
int f_port = 0
 
std::string f_addr
 
char * buf = NULL
 
size_t bufSize = 512
 

Additional Inherited Members

- Static Public Member Functions inherited from XPMP2::SocketNetworking
static std::string GetLastErr ()
 Returns a human-readable text for the last error. More...
 
static std::string GetAddrString (const SockAddrTy &sa, bool withPort=true)
 Convert addresses to string. More...
 

Detailed Description

UDP Multicast, always binding to INADDR_ANY.

Exceptions
XPMP2::NetRuntimeErrorin case of any errors

Constructor & Destructor Documentation

◆ UDPMulticast() [1/2]

XPMP2::UDPMulticast::UDPMulticast ( )
inline

Default constructor is not doing anything.

◆ UDPMulticast() [2/2]

XPMP2::UDPMulticast::UDPMulticast ( const std::string &  _multicastAddr,
int  _port,
const std::string &  _sendIntf,
int  _ttl = 8,
size_t  _bufSize = 512,
unsigned  _timeOut_ms = 0 
)

Constructor creates a socket and binds it to INADDR_ANY and connects to the given multicast address.

◆ ~UDPMulticast()

XPMP2::UDPMulticast::~UDPMulticast ( )
override

makes sure pMCAddr is cleared up

Member Function Documentation

◆ Cleanup()

void XPMP2::UDPMulticast::Cleanup ( )
protected

frees pMCAddr

◆ GetAddrHints()

void XPMP2::UDPMulticast::GetAddrHints ( struct addrinfo &  hints)
overrideprotectedvirtual

returns information from *pMCAddr

Implements XPMP2::SocketNetworking.

◆ GetFamily()

uint8_t XPMP2::UDPMulticast::GetFamily ( ) const
inline

Protocol family.

◆ GetMCAddr()

const std::string& XPMP2::UDPMulticast::GetMCAddr ( ) const
inline

Return formatted multicast address, including port.

◆ IsIPv4()

bool XPMP2::UDPMulticast::IsIPv4 ( ) const
inline

IPv4?

◆ IsIPv6()

bool XPMP2::UDPMulticast::IsIPv6 ( ) const
inline

IPv6?

◆ Join()

void XPMP2::UDPMulticast::Join ( const std::string &  _multicastAddr,
int  _port,
const std::string &  _sendIntf,
int  _ttl = 8,
size_t  _bufSize = 512,
unsigned  _timeOut_ms = 0 
)

Connect to the multicast group.

Exceptions
XPMP2::NetRuntimeErrorin case of any errors

◆ RecvMC()

size_t XPMP2::UDPMulticast::RecvMC ( bool  bSwitchToRecvIntf,
std::string *  _pFromAddr = nullptr,
SockAddrTy _pFromSockAddr = nullptr,
bool *  _pbIntfChanged = nullptr 
)

Receive a multicast, received message is in XPMP2::SocketNetworking::GetBuf()

Parameters
bSwitchToRecvIntfShall all future datagrams be send out on the same interface as we received this message on?
[out]_pFromAddrIf given then the sender adress is written into this string
[out]_pFromSockAddrIf given then the sender adress is written into this string
[out]_pbIntfChangedis set to true if the sending interface has been changed based on the received datagram
Returns
Number of bytes received, 0 in case no data was waiting

◆ SendMC()

size_t XPMP2::UDPMulticast::SendMC ( const void *  _bufSend,
size_t  _bufSendSize 
)

Send a multicast.

Parameters
_bufSendData to send
_bufSendSizeSize of the provided buffer
Returns
Number of bytes sent

◆ SendToAll()

void XPMP2::UDPMulticast::SendToAll ( )

Send future datagrams on all interfaces.

◆ SendToDefault()

void XPMP2::UDPMulticast::SendToDefault ( )

Send future datagrams on default interfaces only (default)

◆ SendToIntf()

void XPMP2::UDPMulticast::SendToIntf ( uint32_t  idx)

Send future datagrams on this particular interface only.

◆ SetSendInterface() [1/2]

void XPMP2::UDPMulticast::SetSendInterface ( const in_addr &  addr)
protected

Set multicast send interface (IPv4 only)

◆ SetSendInterface() [2/2]

void XPMP2::UDPMulticast::SetSendInterface ( uint32_t  ifIdx)
protected

Set multicast send interface.

Member Data Documentation

◆ bSendToAll

bool XPMP2::UDPMulticast::bSendToAll = true
protected

Send out multicast datagrams to all interfaces.

◆ mapSender

std::map<SockAddrTy,std::chrono::time_point<std::chrono::steady_clock> > XPMP2::UDPMulticast::mapSender
protected

Keep a list of sources we received data from to be able to identify new sources.

◆ multicastAddr

std::string XPMP2::UDPMulticast::multicastAddr
protected

the multicast address

◆ oneIntfIdx

uint32_t XPMP2::UDPMulticast::oneIntfIdx = 0
protected

When sending to one interface only, which one?

◆ pMCAddr

struct addrinfo* XPMP2::UDPMulticast::pMCAddr = nullptr
protected

the multicast address


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