我认为这是一个非常简单的问题。
我正在尝试使用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)
有人可以向我解释我做错了什么或替代方法。我应用于服务创建的字符串肯定是有效的,因为它们用于在应用程序的早期注册服务。
答案 0 :(得分:5)
我遇到了同样的问题。事实证明,当事件类型无效时,ServiceInfo.create()不会优雅地告诉您。在我的情况下,我发送&#34; _http._tcp。&#34;作为事件类型。我将我的事件类型更改为&#34; _http._tcp.local&#34;一切都很完美。希望有所帮助。