Hi, folks, <br><br>I'm recently investigating some NIO framework, and I find that Netty is awesome, I'd like to adopt it into our project.<br>But here's my first question: how to detect the conenction timeout on client side?<br>
As the secureChat example shown, client connects to host via code:<br><br><div style="margin-left: 40px;"><i>ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));</i><br></div><br>a <i>ChannelFuture</i> returned immediately, which tells the connection status, e.g. canceled or done, <b>but no TIMEOUT</b>.<br>
<br>by digging some codes, I got this:<br><br><i><u>org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.Boss.processConnectTimeout(Set<SelectionKey>, long)</u><br><br> private void processConnectTimeout(Set<SelectionKey> keys, long currentTimeNanos) {<br>
ConnectException cause = null;<br> for (SelectionKey k: keys) {<br> if (!k.isValid()) {<br> continue;<br> }<br><br> NioClientSocketChannel ch = (NioClientSocketChannel) k.attachment();<br>
if (ch.connectDeadlineNanos > 0 &&<br> currentTimeNanos >= ch.connectDeadlineNanos) {<br><br> if (cause == null) {<br> <b>cause = new ConnectException("connection timed out");</b><br>
}<br><br> ch.connectFuture.setFailure(cause);<br> fireExceptionCaught(ch, cause);<br> close(k);<br> }<br> }<br> }</i><br>
<br>so, from the view above, maybe we can test the timeout status int the <i>ChannelFutureListener</i> via:<br><br><div style="margin-left: 40px;"><i>new ChannelFutureListener() {<br><br></i><div style="margin-left: 40px;">
<i>public void operationComplete(ChannelFuture future) {<br><br></i><div style="margin-left: 40px;"><i>if (future.getCause() instanceof ConnectException) {<br>
</i>
<div style="margin-left: 40px;"><i>// deal with timeout<br>
....<br>
</i></div>
<i>}<br>
</i></div>
<i><br>}<br></i></div><i>}</i><br></div><br clear="all">is that correct? but a little weird, I think.<br><br> <br><br>Thanks & Best Regards!<br><br> ///<br> (. .)<br> --------ooO--(_)--Ooo--------<br>
| Nick Tan |<br> -----------------------------<br><br>