|
XPMP2
X-Plane multiplayer library 2 - using instancing
|
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... | |
UDP Multicast, always binding to INADDR_ANY.
| XPMP2::NetRuntimeError | in case of any errors |
|
inline |
Default constructor is not doing anything.
| 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.
|
override |
makes sure pMCAddr is cleared up
|
protected |
frees pMCAddr
|
overrideprotectedvirtual |
returns information from *pMCAddr
Implements XPMP2::SocketNetworking.
|
inline |
Protocol family.
|
inline |
Return formatted multicast address, including port.
|
inline |
IPv4?
|
inline |
IPv6?
| 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.
| XPMP2::NetRuntimeError | in case of any errors |
| 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()
| bSwitchToRecvIntf | Shall all future datagrams be send out on the same interface as we received this message on? | |
| [out] | _pFromAddr | If given then the sender adress is written into this string |
| [out] | _pFromSockAddr | If given then the sender adress is written into this string |
| [out] | _pbIntfChanged | is set to true if the sending interface has been changed based on the received datagram |
0 in case no data was waiting | size_t XPMP2::UDPMulticast::SendMC | ( | const void * | _bufSend, |
| size_t | _bufSendSize | ||
| ) |
Send a multicast.
| _bufSend | Data to send |
| _bufSendSize | Size of the provided buffer |
| void XPMP2::UDPMulticast::SendToAll | ( | ) |
Send future datagrams on all interfaces.
| void XPMP2::UDPMulticast::SendToDefault | ( | ) |
Send future datagrams on default interfaces only (default)
| void XPMP2::UDPMulticast::SendToIntf | ( | uint32_t | idx | ) |
Send future datagrams on this particular interface only.
|
protected |
Set multicast send interface (IPv4 only)
|
protected |
Set multicast send interface.
|
protected |
Send out multicast datagrams to all interfaces.
|
protected |
Keep a list of sources we received data from to be able to identify new sources.
|
protected |
the multicast address
|
protected |
When sending to one interface only, which one?
|
protected |
the multicast address