Boardy
Boardy

Reputation: 36223

Network Service Discovery

I am looking at making a client/server application for Android (Client) and Server (Windows).

The purpose of the app is from the server (PC) it allows the user to scan the network for devices that are compatible with my C# application and then can send messages to and from the client and the server.

I've been reading the Android documentation and found the Network Discovery Service in android at http://developer.android.com/training/connect-devices-wirelessly/nsd.html.

My understanding of how this works is, the android application, sends a broadcast message with the service name, IP and port number that other devices can connect to it via. Therefore in my case the C# would receive this broadcast message and decide whether the service is something my C# application can support, and if so, then establish the socket connection to the android device with the details from the broadcast.

As I say I've found the Android Developer tutorial for registering the service, but I can't find anything for how C# can find this broadcast message and act upon it.

Upvotes: 4

Views: 5219

Answers (2)

Uberbot7147
Uberbot7147

Reputation: 49

This may be helpful: http://justanapplication.wordpress.com/2013/11/20/service-discovery-in-android-and-ios-part-eight-ios-take-four/

I used this once, the first few pages list how to receive callbacks from a DNS discovery service inside an android app, like greenapps was suggesting. Although it may not be the exact method you are using as your method only finds compatible devices; this at least may be a starting point.

Upvotes: -1

Rogier van het Schip
Rogier van het Schip

Reputation: 937

@greenapps is right, the server should broadcast. Therefore, use the Network Service Discovery to discover a service being broadcast by your C# service.

Android's NsdManager class has a tutorial for doing this. It works using "DNS based service discovery", with the official spec listed here. I believe this is the DNS Service Discovery (DNS-SD) standard.

Your server will have to broadcast. You should be able to do this using this question, which covers DNS SRV, one of DNS-SDs foundations.

Of course, the C# broadcast service type will have to match the SERVICE_TYPE string argument in your Android code:

mNsdManager.discoverServices(
    SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener);

Upvotes: 3

Related Questions