socketChannel.read(buf) hangs forever
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