protected void removeItemsFromList(final NsdServiceInfo serviceInfo) {
   Iterator<NsdServiceInfo> iter = mNsdList.iterator();
   while (iter.hasNext()) {
     NsdServiceInfo tmpService = iter.next();
     if (tmpService.getHost().equals(serviceInfo.getHost())) {
       iter.remove();
     }
   }
   listUpdateNotify();
 }
 public void clickConnect(View v) {
   NsdServiceInfo service = mNsdHelper.getChosenServiceInfo();
   if (service != null) {
     Log.d(TAG, "Connecting.");
     mConnection.connectToServer(service.getHost(), service.getPort());
   } else {
     Log.d(TAG, "No service to connect to!");
   }
 }
  protected void addItemsToList(final NsdServiceInfo serviceInfo) {
    // this runs on UI thread using pingAsyncTask class

    /*
     * for (NsdServiceInfo si:mNsdList) { if
     * (si.getServiceName().equals(serviceInfo.getServiceName())) { // don't
     * add this item to list return; } }
     */

    Iterator<NsdServiceInfo> iter = mNsdList.iterator();
    while (iter.hasNext()) {
      NsdServiceInfo tmpService = iter.next();
      if (tmpService.getHost().equals(serviceInfo.getHost())) {
        iter.remove();
      }
    }
    mNsdList.add(serviceInfo);
    listUpdateNotify();
  }
  public void registerService(int port) {
    NsdServiceInfo serviceInfo = new NsdServiceInfo();
    serviceInfo.setPort(port);
    serviceInfo.setServiceName(mServiceName);
    serviceInfo.setServiceType(SERVICE_TYPE);

    mNsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, mRegistrationListener);

    System.out.println(
        TAG + " Registered " + String.valueOf(serviceInfo.getHost()) + " " + serviceInfo.getPort());
  }
 @Override
 public View getView(int position, View view, ViewGroup parent) {
   ViewHolder holder;
   if (view == null) {
     view = LayoutInflater.from(getContext()).inflate(R.layout.list_item_server, parent, false);
     holder = new ViewHolder();
     holder.name = (TextView) view.findViewById(R.id.lblDeviceName);
     holder.details = (TextView) view.findViewById(R.id.lblDeviceDetail);
     view.setTag(holder);
   } else {
     holder = (ViewHolder) view.getTag();
   }
   NsdServiceInfo serviceInfo = getItem(position);
   holder.name.setText(serviceInfo.getServiceName());
   holder.details.setText(serviceInfo.getHost().toString());
   return view;
 }
 @Override
 protected Boolean doInBackground(NsdServiceInfo... nsi) {
   int count = nsi.length;
   if (count != 1) {
     Log.e(TAG, "found more then one NsdServiceInfo, dropping");
   }
   mNsdServiveInfo = nsi[0];
   InetAddress tmpIP = mNsdServiveInfo.getHost();
   boolean ret;
   try {
     ret = tmpIP.isReachable(10000);
     return ret;
   } catch (IOException e) {
     e.printStackTrace();
     return false;
   }
 }
 public void updatePd40DeviceIp(NsdServiceInfo info) {
   String ip = info.getHost().toString().substring(1);
   Toast.makeText(getActivity(), "Chosen device IP: " + ip, 0).show();
   ((ScratchpadActivity) getActivity()).getTcpService().restartServiceThreadWithIp(ip);
 }