gpt4 book ai didi

java - 重新注册服务 JMDNS

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:18:00 25 4
gpt4 key购买 nike

我有一个我认为非常简单的问题。

我正在尝试使用 JmDNS 来广播我已经成功完成的服务,但是当应用程序暂停时,我想取消注册服务,然后在恢复应用程序时重新注册服务。

然而,我在执行此操作时遇到了问题。代码如下:

//I use jmdns.create again before these lines which I don't know if i should?

mServiceInfo = ServiceInfo.create(registeredServiceName, registeredServiceType, registeredServicePort,"Hello");

try {

jmdnsNetworkDiscoveryManager.registerService(mServiceInfo);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.i(TAG, "Service Registration Error");
}

当我尝试这个时,我得到了这个让我困惑的错误日志:

07-29 10:38:13.099: W/DNSStateTask(28769): java.lang.StringIndexOutOfBoundsException: length=37; regionStart=0; regionLength=-1
07-29 10:38:13.099: W/DNSStateTask(28769): at java.lang.String.startEndAndLength(String.java:593)

07-29 10:38:13.099: W/DNSStateTask(28769): at java.lang.String.substring(String.java:1474)

07-29 10:38:13.099: W/DNSStateTask(28769): at javax.jmdns.impl.ServiceInfoImpl.decodeQualifiedNameMapForType(ServiceInfoImpl.java:292)

07-29 10:38:13.099: W/DNSStateTask(28769): at javax.jmdns.impl.DNSEntry.<init>(DNSEntry.java:47)

07-29 10:38:13.099: W/DNSStateTask(28769): at javax.jmdns.impl.DNSQuestion.<init>(DNSQuestion.java:220)

07-29 10:38:13.099: W/DNSStateTask(28769): at javax.jmdns.impl.DNSQuestion$AllRecords.<init>(DNSQuestion.java:184)

07-29 10:38:13.099: W/DNSStateTask(28769): at javax.jmdns.impl.DNSQuestion.newQuestion(DNSQuestion.java:245)

07-29 10:38:13.099: W/DNSStateTask(28769): at javax.jmdns.impl.tasks.state.Prober.buildOutgoingForInfo(Prober.java:131)

07-29 10:38:13.099: W/DNSStateTask(28769): at javax.jmdns.impl.tasks.state.DNSStateTask.run(DNSStateTask.java:125)

07-29 10:38:13.099: W/DNSStateTask(28769): at java.util.Timer$TimerImpl.run(Timer.java:284)

07-29 10:38:13.104: W/JmDNSImpl(28769): RECOVERING
07-29 10:38:13.119: W/DNSStateTask(28769): Canceler(192-168-2-2.local.).run() exception
07-29 10:38:13.119: W/DNSStateTask(28769): java.lang.StringIndexOutOfBoundsException: length=37; regionStart=0; regionLength=-1

07-29 10:38:13.119: W/DNSStateTask(28769): at java.lang.String.startEndAndLength(String.java:593)

07-29 10:38:13.119: W/DNSStateTask(28769): at java.lang.String.substring(String.java:1474)

07-29 10:38:13.119: W/DNSStateTask(28769): at javax.jmdns.impl.ServiceInfoImpl.decodeQualifiedNameMapForType(ServiceInfoImpl.java:292)

07-29 10:38:13.119: W/DNSStateTask(28769): at javax.jmdns.impl.DNSEntry.<init>(DNSEntry.java:47)

07-29 10:38:13.119: W/DNSStateTask(28769): at javax.jmdns.impl.DNSRecord.<init>(DNSRecord.java:46)

07-29 10:38:13.119: W/DNSStateTask(28769): at javax.jmdns.impl.DNSRecord$Service.<init>(DNSRecord.java:647)

07-29 10:38:13.119: W/DNSStateTask(28769): at javax.jmdns.impl.ServiceInfoImpl.answers(ServiceInfoImpl.java:1195)

07-29 10:38:13.119: W/DNSStateTask(28769): at javax.jmdns.impl.tasks.state.Canceler.buildOutgoingForInfo(Canceler.java:117)

07-29 10:38:13.119: W/DNSStateTask(28769): at javax.jmdns.impl.tasks.state.DNSStateTask.run(DNSStateTask.java:125)

07-29 10:38:13.119: W/DNSStateTask(28769): at java.util.Timer$TimerImpl.run(Timer.java:284)

有人可以向我解释我做错了什么或其他方法吗?我应用于服务创建的字符串绝对有效,因为它们用于在应用程序的早期注册服务。

最佳答案

我遇到了同样的问题。事实证明,当您的事件类型无效时,ServiceInfo.create() 并没有优雅地告诉您。在我的例子中,我发送的是“_http._tcp”。作为事件类型。我将事件类型更改为“_http._tcp.local”,一切正常。希望对您有所帮助。

关于java - 重新注册服务 JMDNS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17920932/

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