stammen / dnssd-uwp

This project is no longer being supported. It is sample code only.
MIT License
6 stars 5 forks source link

Can advertising be started without RegisterStreamSocketListenerAsync? #3

Open ewmailing opened 6 years ago

ewmailing commented 6 years ago

I am concerned about this initialization code in DnssdService.cpp


        mSocket = ref new StreamSocketListener();
        mSocketToken = mSocket->ConnectionReceived += ref new TypedEventHandler<StreamSocketListener^, StreamSocketListenerConnectionReceivedEventArgs ^>(this, &DnssdService::OnConnect);
        create_task(mSocket->BindServiceNameAsync(mPort)).get();
        unsigned short port = static_cast<unsigned short>(_wtoi(mSocket->Information->LocalPort->Data()));
        mService = ref new DnssdServiceInstance(L"dnssd." + mServiceName + L".local", hostName, port);
        return create_task(mService->RegisterStreamSocketListenerAsync(mSocket));

It seems like you are creating a socket to start advertising the service. This worries me for the following reasons:

So I'm hoping you can tell me that this above code is unnecessary and there is another way to start advertising.

Or if not, is there a workaround? How bad is it if I create that socket on a random port ("") and never use it? But I set the DnssdServiceInstance to the real port of my service. Besides wasting a socket, would this work?

Cyrille-de-Brebisson commented 4 years ago

Hello,

Have you ever found a solution to this issue? I have exactly the same problem that I am trying to fix...

Thanks, Cyrille