如何在使用网络服务发现代码时获取IP

时间:2016-11-24 02:02:57

标签: android

我尝试使用“网络服务发现”示例代码来查找服务。 来源提供了here

NsdHelper类发现服务代码如下:

public void onServiceFound(NsdServiceInfo service) {
    Log.d(TAG, "Service discovery success" + service);
    if (!service.getServiceType().equals(SERVICE_TYPE)) {
        Log.d(TAG, "Unknown Service Type: " + service.getServiceType());
    } else if (service.getServiceName().equals(mServiceName)) {
        Log.d(TAG, "Same machine: " + mServiceName);
    } else if (service.getServiceName().contains(mServiceName)){
        mNsdManager.resolveService(service, mResolveListener);
    }
}

我尝试使用“service.getHost()”,但它变为null。 我怎样才能获得每项服务的IP?

0 个答案:

没有答案