Overview
- Install Bonjour64.msi.
You can install Bonjour SDK to see examples in several laguages.
- Callbacks must be static, so any information you want to provide, use void* context parameter
- You can set several searchers. Then wait with select function until some answer is ready and call it with DNSServiceProcessResult(?), where ? is first parameter of searcher function or read (***) for other possibility.
- DNSServiceProcessResult inside run callback(s).
- searcher DNSServiceBrowse. if regtype == "_services._dns-sd._udp", it looks for all regtypes on network, otherwise it looks for instances of given regtype (in first case again call with one or more concrete regtypes)
- searcher DNSServiceResolve for resolve concrete instance
- searcher DNSServiceGetAddrInfo and DNSServiceQueryRecord
DNSServiceBrowse, DNSServiceQueryRecord usually runs indefinitely looking for change
do not forget DNSServiceRefDeallocate on DNSServiceRef given to DNSServiceResolve and DNSServiceGetAddrInfo.
- You need dns_sd.h and dnssd.lib
What is not clear at first glance
- DNSServiceProcessResult might run not only one, but several callbacks.
- err -65563 == kDNSServiceErr_ServiceNotRunning, Start Bonjour Service. It sometimes stop working.
- You have two possibilities (***):
- 1. DNSServiceRef client = NULL;
DNSServiceErrorType err = DNSServiceBrowse(&client,
And then use DNSServiceRefSockFD(client) for select function
2. DNSServiceErrorType err = DNSServiceCreateConnection(&clientDefault);
DNSServiceRef client = clientDefault;
DNSServiceErrorType err = DNSServiceBrowse(&client,
And then use DNSServiceRefSockFD(clientDefault) for select function
and so you can use client Default for many calls
- You will use sockets on windows:
http://stackoverflow.com/questions/9153911/is-there-a-difference-between-winsock-h-and-winsock2-h
http://stackoverflow.com/questions/14094457/winsock-h-winsock2-h-which-to-use
https://msdn.microsoft.com/en-us/library/windows/desktop/ms737629(v=vs.85).aspx
#include<winsock2.h> before #include<windows.h> and also before #include<dns_sd.h> which includes windows.h
i.e.
#include <winsock2.h>
#include <ws2tcpip.h>
#include <Iphlpapi.h>
#include <process.h>
#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "Iphlpapi.lib")
#include <dns_sd.h>
No comments:
Post a Comment