Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

socketChannel.read(buf) hangs forever

phantasmoMar 15 2007 — edited Mar 18 2007
Hey there :)
I hope this is the right place to ask a question like this.
I am writing a client-server app utilizing SocketChannels.
The client side does this:

ByteBuffer buf = ByteBuffer.allocateDirect(1024);
buf.clear();
buf.put("Hello World".getBytes());
buf.flip();
int numBytesWritten = sc.write(buf); //11

and the server does this:

if (selKey.isValid() && selKey.isReadable()) {
SocketChannel s1Channel = (SocketChannel)selKey.channel();
byte[] bytes = new byte[1024];
ByteBuffer buf = ByteBuffer.wrap(bytes);
buf.clear();
int numBytesRead = s1Channel.read(buf);

and at the last line it just hangs forever. I tried changing buffer size and tinkering with everything that came to my mind but nothing helped. Does anyone know what might be the problem here, I'm confused.

tnx
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 15 2007
Added on Mar 15 2007
5 comments
666 views