使用线程睡眠然后我们不能得到这种类型的错误
@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();
}
}
}
这对我有用,谢谢