Locates mDNS services by issuing queries. More...

#include <Server.h>

Inheritance diagram for mDNS::Server:
Collaboration diagram for mDNS::Server:

Public Types

using MessageDelegate = Delegate< bool(Message &message)>
 Callback to be invoked for each received message. More...
 
using PacketDelegate = Delegate< bool(IpAddress remoteIP, uint16_t remotePort, const uint8_t *data, size_t length)>
 Callback to be invoked with raw data (debugging, etc.) More...
 

Public Member Functions

 ~Server ()
 
bool begin ()
 
void end ()
 
bool restart ()
 
void addHandler (Handler &handler)
 Set callback to be invoked for each received message. More...
 
void removeHandler (Handler &handler)
 Remove a message handler. More...
 
void onSend (MessageDelegate callback)
 Set callback to be invoked before sending a message. More...
 
void onPacket (PacketDelegate callback)
 Set callback to be invoked for raw received data, before parsing. More...
 
bool search (const String &hostname, ResourceType type=ResourceType::PTR)
 Send a multicast query. More...
 
bool send (Message &message)
 Send an mDNS message containing questions/answers. More...
 

Protected Member Functions

void onReceive (pbuf *buf, IpAddress remoteIP, uint16_t remotePort) override
 
- Protected Member Functions inherited from UdpConnection
bool initialize (udp_pcb *pcb=nullptr)
 
 UdpConnection ()
 
 UdpConnection (UdpConnectionDataDelegate dataHandler)
 
virtual ~UdpConnection ()
 
virtual bool listen (int port)
 
virtual bool connect (IpAddress ip, uint16_t port)
 
virtual void close ()
 
virtual bool send (const char *data, int length)
 
bool sendString (const char *data)
 
bool sendString (const String &data)
 
virtual bool sendTo (IpAddress remoteIP, uint16_t remotePort, const char *data, int length)
 
bool sendStringTo (IpAddress remoteIP, uint16_t remotePort, const char *data)
 
bool sendStringTo (IpAddress remoteIP, uint16_t remotePort, const String &data)
 
bool setMulticast (IpAddress ip)
 Sets the UDP multicast IP. More...
 
bool setMulticastTtl (size_t ttl)
 Sets the UDP multicast Time-To-Live(TTL). More...
 
- Protected Member Functions inherited from IpConnection
bool joinMulticastGroup (IpAddress localIp, IpAddress multicastIp)
 Uses IGMP to add a local network interface to multicast group. More...
 
bool joinMulticastGroup (IpAddress multicastIp)
 Uses IGMP to add all local network interfaces to multicast group. More...
 
bool leaveMulticastGroup (IpAddress localIp, IpAddress multicastIp)
 Uses IGMP to remove a local network interface from multicast group. More...
 
bool leaveMulticastGroup (IpAddress multicastIp)
 Uses IGMP to remove all local network interfaces from multicast group. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from UdpConnection
static void staticOnReceive (void *arg, struct udp_pcb *pcb, struct pbuf *p, LWIP_IP_ADDR_T *addr, u16_t port)
 
- Protected Attributes inherited from UdpConnection
udp_pcb * udp = nullptr
 
UdpConnectionDataDelegate onDataCallback = nullptr
 

Detailed Description

Locates mDNS services by issuing queries.

Member Typedef Documentation

◆ MessageDelegate

Callback to be invoked for each received message.

Return values
boolSee onSend()

◆ PacketDelegate

using mDNS::Server::PacketDelegate = Delegate<bool(IpAddress remoteIP, uint16_t remotePort, const uint8_t* data, size_t length)>

Callback to be invoked with raw data (debugging, etc.)

Return values
boolSee onPacket()

Constructor & Destructor Documentation

◆ ~Server()

mDNS::Server::~Server ( )

Member Function Documentation

◆ addHandler()

void mDNS::Server::addHandler ( Handler handler)
inline

Set callback to be invoked for each received message.

Parameters
callbackReturn false from callback to prevent message being passed to other clients

◆ begin()

bool mDNS::Server::begin ( )

◆ end()

void mDNS::Server::end ( )

◆ onPacket()

void mDNS::Server::onPacket ( PacketDelegate  callback)
inline

Set callback to be invoked for raw received data, before parsing.

Parameters
callbackReturn true from callback to actually send packet

◆ onReceive()

void mDNS::Server::onReceive ( pbuf *  buf,
IpAddress  remoteIP,
uint16_t  remotePort 
)
overrideprotectedvirtual

Reimplemented from UdpConnection.

◆ onSend()

void mDNS::Server::onSend ( MessageDelegate  callback)
inline

Set callback to be invoked before sending a message.

Parameters
callbackReturn true from callback to actually send packet

◆ removeHandler()

void mDNS::Server::removeHandler ( Handler handler)
inline

Remove a message handler.

Note
If there are no more handlers then consider setting a timeout and then shutting the server down.

◆ restart()

bool mDNS::Server::restart ( )
inline

◆ search()

bool mDNS::Server::search ( const String hostname,
ResourceType  type = ResourceType::PTR 
)

Send a multicast query.

Parameters
hostnameName to find, e.g. "_googlecast._tcp.local"
type
Return values
boolfalse if parameters failed validation or UDP request could not be sent

◆ send()

bool mDNS::Server::send ( Message message)

Send an mDNS message containing questions/answers.

Return values
booltrue if message sent successfully

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