errorCodes对于Android NSD onResolveFailed()意味着什么

时间:2015-05-04 09:41:55

标签: android nsd

Android Network Service Discovery为我们提供了onResolveFailed()回调,如下所示:

NsdManager.ResolveListener mResolveListener = new NsdManager.ResolveListener() {

    @Override
    public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
        // Called when the resolve fails. Use the error code to debug.
        Log.e(TAG, "Resolve failed " + errorCode);
    }
};

就我而言,我得到了errorCode 3。

这些erorCodes代表什么?我会在哪里找到指定的内容?

2 个答案:

答案 0 :(得分:6)

它就在您链接到

的文档中

enter image description here

答案 1 :(得分:1)

使用线程睡眠,那么我们将无法得到此类错误

            @Override
    public void onServiceFound(final NsdServiceInfo service) {

       if(service.getServiceName()!=null) {


              try {

            Log.d(TAG, "Service discovery success = " + service.toString());

            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


                  mNsdManager.resolveService(service,new NsdManager.ResolveListener() {

                      @Override
                      public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
                          // Called when the resolve fails.  Use the error code to debug.
                          Log.e(TAG, "Resolve failed" + errorCode);


                      }

                      @Override
                      public void onServiceResolved(NsdServiceInfo serviceInfo) {

                          Log.e(TAG, "Resolve Succeeded. " + serviceInfo);


                          String mHostFound = serviceInfo.getHost().getHostAddress();
                          int mPortFound = serviceInfo.getPort();


                          System.out.println(serviceInfo.getServiceName());
                          System.out.println(mHostFound);
                          System.out.println(mPortFound);

                      }
                  });


              } catch (Exception e) {
                  e.printStackTrace();
              }

            }


    }                

这对我来说非常感谢