4

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Boardy
  • 35,417
  • 104
  • 256
  • 447
  • No. Your C# server should broadcast messages. Your android client would listen to it and determine if the service can be used. Upon which the client connects to the server. A server/service cannot connect to a client. – greenapps Jun 12 '14 at 18:52
  • Ah that makes sense, have you got any tutorials for doing that as can't seem to find anything – Boardy Jun 12 '14 at 21:27

2 Answers2

2

@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);
Community
  • 1
  • 1
  • Ah, didn't realise it would use DNS. So I guess the DNS server would need to have the details within its record so a device wanting it knows what IP to send the request to. This unfortunately wouldn't work for me as target audience likely wouldn't know ho to modify dns records and its for an internal home network so may not be able to add/change records. Thanks though – Boardy Jun 16 '14 at 15:21
  • I'm not sure you need to configure the DNS server. As far as I could tell, this is the same protocol as the one used for wireless printers, and I sure never set up a DNS server for that. Give it a try! – Rogier van het Schip Jun 18 '14 at 12:56
-1

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.