N
nooneinparticular314159
I'm calling SocketChannel.finishConnect, which is supposed to return
false unless a connection succeeds. However, when I try to connect, I
get a "connection refused" IOException. This makes sense, since the
server I'm trying to connect to is not up yet. But it has the side
effect of closing the channel! That means that I have to keep creating
a new SocketChannel and registering it with my Selector in the
exception handler until it actually connects. This seems like it
defeats the purpose of using a selector on a channel in the first
place.
My questions:
1) Why is the channel being closed? Shouldn't finishConnect just
return false so that I can try again?
2) Is there a way to prevent it from being closed?
3) Is there some alternative where I don't have to keep recreating a
re-registering the channel?
Thanks!
false unless a connection succeeds. However, when I try to connect, I
get a "connection refused" IOException. This makes sense, since the
server I'm trying to connect to is not up yet. But it has the side
effect of closing the channel! That means that I have to keep creating
a new SocketChannel and registering it with my Selector in the
exception handler until it actually connects. This seems like it
defeats the purpose of using a selector on a channel in the first
place.
My questions:
1) Why is the channel being closed? Shouldn't finishConnect just
return false so that I can try again?
2) Is there a way to prevent it from being closed?
3) Is there some alternative where I don't have to keep recreating a
re-registering the channel?
Thanks!