1. Are you ready for the Galaxy S20? Here is everything we know so far!

Android Network Service Discovery

Discussion in 'Android Development' started by Wuffle, Mar 20, 2016.

  1. Wuffle

    Wuffle Lurker
    Thread Starter

    I am using androids built in Network Service Discovery to find device B from device A however it doesn't discover the service from A but finds everything else printers etc.

    The Register service triggers the call back informing me the service was registered on A but i still cant find it on Device B.

    Code (Text):
    1.  
    2. public void registerService(int port) {
    3.     tearDown();
    4.     NsdServiceInfo serviceInfo  = new NsdServiceInfo();
    5.     serviceInfo.setPort(port);
    6.     serviceInfo.setServiceName(mServiceName);
    7.     serviceInfo.setServiceType(SERVICE_TYPE);
    8.     initializeRegistrationListener();
    9.     manager.registerService(
    10.             serviceInfo, NsdManager.PROTOCOL_DNS_SD, mRegistrationListener);
    11.  
    12. }
    13.  
    14. @Override
    15. public void onServiceRegistered(NsdServiceInfo NsdServiceInfo) {
    16.     mServiceName = NsdServiceInfo.getServiceName();
    17.     Log.d("Quiz", "Regsistered name " + NsdServiceInfo.getServiceName());
    18.     Log.d("Quiz", "Regsistered port " + String.valueOf(NsdServiceInfo.getPort()));
    19.     Log.d("Quiz", "Service Type " + NsdServiceInfo.getServiceType());
    20. }
    21.  
    22.  
    23. public void discoverServices() {
    24.     stopDiscovery();  // Cancel any existing discovery request
    25.     initializeDiscoveryListener();
    26.     manager.discoverServices(
    27.             SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener);
    28. }
    29.  
    30. @Override
    31. public void onServiceFound(NsdServiceInfo service) {
    32.     Log.d("Quiz", "Services " +service.getServiceName());
    33.     Log.d("Quiz", "Port " +String.valueOf(service.getPort()));
    34.     Log.d("Quiz", "Service Type " + service.getServiceType());
    35.     boolean found=false;
    36.     if (service.getServiceType().equals(SERVICE_TYPE)) {
    37.         if(servers.size()==0){
    38.             servers.add(service.getServiceName());
    39.           //  Log.d("Quiz", "Services Added");
    40.         }
    41.         for(int i=0;i<servers.size();i++){
    42.             if(servers.get(i).equals(service.getServiceName()))
    43.             {
    44.                 found=true;
    45.             }
    46.         }
    47.     }
    48.     if(found==false) {
    49.         servers.add(service.getServiceName());
    50.       //  Log.d("Quiz", "Services Added");
    51.     }
    52. }
    53.  
    I am adding the services found to a list from which i update a list view for those wondering what the extra code is for.

    Anyone have any ideas as to why i cant find the service?

    Thanks in advance.
     


Loading...
Similar Threads - Android Network Service
  1. kaneelschep
    Replies:
    2
    Views:
    126
  2. PLYPLA
    Replies:
    1
    Views:
    185
  3. serumaninho
    Replies:
    0
    Views:
    188
  4. denerex
    Replies:
    0
    Views:
    159
  5. Splinternet
    Replies:
    6
    Views:
    746
  6. ayoubhim
    Replies:
    0
    Views:
    246
  7. corvairbob
    Replies:
    0
    Views:
    248
  8. phantomsdad
    Replies:
    5
    Views:
    360
  9. bazzaman
    Replies:
    4
    Views:
    652
  10. Asad7654677
    Replies:
    4
    Views:
    1,340

Share This Page

Loading...