예제 #1
0
  /** Register a DNS-SD service (to be discoverable through Bonjour/Avahi). */
  protected void announceService() {
    nsdRegistrationListener =
        new NsdManager.RegistrationListener() {
          @Override
          public void onServiceRegistered(NsdServiceInfo serviceInfo) {
            logger.debug("onServiceRegistered()");
          }

          @Override
          public void onRegistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
            logger.debug("onRegistrationFailed()");
          }

          @Override
          public void onServiceUnregistered(NsdServiceInfo serviceInfo) {
            logger.debug("onServiceUnregistered()");
          }

          @Override
          public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
            logger.debug("onUnregistrationFailed()");
          }
        };

    NsdServiceInfo serviceInfo = new NsdServiceInfo();
    serviceInfo.setServiceName("primitive ftpd");
    serviceInfo.setServiceType("_" + getServiceName() + "._tcp.");
    serviceInfo.setPort(getPort());

    NsdManager nsdManager = (NsdManager) getSystemService(Context.NSD_SERVICE);

    nsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, nsdRegistrationListener);
  }
예제 #2
0
  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);
  }
 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!");
   }
 }
예제 #4
0
 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();
 }
예제 #5
0
 @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;
 }
예제 #6
0
  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();
  }
예제 #7
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   View v = convertView;
   final NsdServiceInfo item = mNsdList.get(position);
   if (v == null) {
     LayoutInflater li =
         (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     v = li.inflate(R.layout.generic_list_item, null);
   }
   if (item != null) {
     TextView textView = (TextView) v;
     if (textView != null) {
       textView.setText(item.getServiceName().replace("-", " - "));
       textView.setOnClickListener(
           new OnClickListener() {
             public void onClick(View v) {
               updatePd40DeviceIp(item);
             }
           });
     }
   }
   return v;
 }
예제 #8
0
  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());
  }
예제 #9
0
 @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;
   }
 }
예제 #10
0
 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);
 }