Skip to content

Can advertising be started without RegisterStreamSocketListenerAsync? #3

@ewmailing

Description

@ewmailing

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:

  • I am trying to add Windows 10 Network Service Discovery to an existing Win32 app (per what this project example is demonstrating). This app already creates its own sockets and I'm worried that this block of code will create a conflicting socket on the same port, which will prevent either my network code from working or prevent this registration from starting.

  • The Zeroconf protocol shouldn't require that the socket and advertisement be explicitly entangled. It is actually possible for one machine to advertise services running on a completely different machine on the same network. Bonjour Sleep Proxy is a fancy example of this.

  • My code is a cross-platform codebase and I currently have wrapper interfaces around Apple Bonjour, Avahi (Linux), and Android Network Service Discovery. None of these require an explicit socket to be bound to start advertisement, so this creates a difficult impedance mismatch to handle.

  • Even if I could alter the interfaces to handle the additional socket needed, my code is based on Winsock. So I am not familiar with any way to bridge a Winsock to a StreamSocketListener().

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions