gpt4 book ai didi

Android NSD 主机返回 NULL

转载 作者:行者123 更新时间:2023-11-29 02:37:01 25 4
gpt4 key购买 nike

我目前正在使用网络服务发现来检测本地网络上的 HTTP 服务。我使用了 Google Android NSDChat 项目示例,它只向我返回主机名,但是主机 IP 地址为 NULL。

这是我的函数,它将返回主机名

    public void onServiceFound(NsdServiceInfo service) {

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

//pref.putString("name", service.getServiceName());
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);
}


}


public void initializeResolveListener() {

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);
}

@Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
Log.e(TAG, "Resolve Succeeded. " + serviceInfo);

if (serviceInfo.getServiceName().equals(mServiceName)) {
Log.d(TAG, "Same IP.");
return;
}
mService = serviceInfo;
int port = mService.getPort();
host = mService.getHost(); // getHost() will work now
Log.d(TAG, "Service discovery success" + host );

}
};
}

最佳答案

我遇到了类似的问题,我找到了这个网站。然而,在尝试之后,它并没有奏效。

Host is null in NsdServiceInfo of NsdManager.DiscoveryListener.onServiceFound

关于Android NSD 主机返回 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46438556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com