6

I have what I thought would be quite a simple problem.

I'm trying to use JmDNS to broadcast a service which I've managed to do successfully, however when the app is paused, I want to unregister a service and then on resuming the app, reregister the service.

I am however running into issues doing this. The code is below:

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

When I try this I get this error log which is confusing me:

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)

Can someone explain to me what I'm doing wrong or an alternative approach. The strings I apply to the service creation are definitely valid as they are used to register a service earlier in the application.

4

1 回答 1

5

我有同样的问题。事实证明,ServiceInfo.create() 不会优雅地告诉您您的事件类型何时无效。就我而言,我发送的是“_http._tcp”。作为事件类型。我将事件类型更改为“_http._tcp.local”,一切正常。希望有帮助。

于 2014-07-11T04:07:41.397 回答