I am having a problem with creating a SocketChannel which can read
data. Here is the
relevant code snippet (from the code for my networking client):
SocketChannel channel = SocketChannel.open();
channel.configureBlocking(false);
channel.connect(new InetSocketAddress(addr, port));
while(!channel.finishConnect())
try{
Thread.sleep(10);
}catch(InterruptedException e){
System.out.println("Interrupted");
}
channel.register(selector, channel.validOps());
System.out.println("Socket Readable: " +
channel.keyFor(selector).isReadable());
This creates a SocketChannel fine, and I can write data to it (and it
is read by the server fine), but
when I run it I find that the socket is not readable, so I can't send
any data back from the server!
Any ideas what could be going wrong?
Thanks in advance for the help
- Iain