By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,468 Members | 1,859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,468 IT Pros & Developers. It's quick & easy.

Making a readable SocketChannel (using NIO package)

P: n/a
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
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.