AlbinTheander / MeQanTT

MQTT library
64 stars 39 forks source link

java.nio.channels.UnresolvedAddressException #1

Open ghost opened 12 years ago

ghost commented 12 years ago

Notice this happening on Android phones and Bug Labs Angstrum linux devices (sporadically), but not on Mac testing using NettyClient.

Caught exception: java.nio.channels.UnresolvedAddressException
java.nio.channels.UnresolvedAddressException
    at sun.nio.ch.Net.checkAddress(Net.java:48)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:505)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:140)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:103)
    at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60)
    at org.jboss.netty.channel.Channels.connect(Channels.java:541)
    at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:210)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)
    at com.albin.mqtt.IsidoreyClient.connect(IsidoreyClient.java:75)
    at com.albin.mqtt.IsidoreyClient.connect(IsidoreyClient.java:50)
    at bugcam_helloworld.servicetracker.BUGcam_helloworldServiceTracker.connect(BUGcam_helloworldServiceTracker.java:134)
    at bugcam_helloworld.servicetracker.BUGcam_helloworldServiceTracker.pubsub(BUGcam_helloworldServiceTracker.java:113)
    at bugcam_helloworld.servicetracker.BUGcam_helloworldServiceTracker.initServices(BUGcam_helloworldServiceTracker.java:84)
    at com.buglabs.application.AbstractServiceTracker.<init>(AbstractServiceTracker.java:73)
    at bugcam_helloworld.servicetracker.BUGcam_helloworldServiceTracker.<init>(BUGcam_helloworldServiceTracker.java:28)
    at bugcam_helloworld.Activator.start(Activator.java:20)
    at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:633)
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:1822)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:1739)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1143)
    at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
    at java.lang.Thread.run(Thread.java:636)
gfhuertac commented 12 years ago

Same issue happeninig here.

vuamitom commented 11 years ago

I encountered this issue on Android while testing over 3G.

AlbinTheander commented 11 years ago

The base reason for this problem is that the host you're trying to connect to can't be found. This doesn't mean that there is anything wrong with your host or host-name. When Android is switching network (different 3G-networks, 3G to WiFi, etc.) it sometimes takes a while before the DNS lookup is working correctly.

That being said, the MeQanTT API should handle this (and other possible problems) better. Wrapping the exception in a well documented exception, for example. Or even adding some retry functionality. As it is right now, you really need to wrap the connect call in a try-catch clause.

If I get a reason to return to this project, I'll add some error handling. Until then, I'm very grateful for anyone wanting to add it and give me a pull request. Hint, hint... :-)