I have a Client - Server java nio application. In some cases I need to handle situations like that:
on Server:
SocketChannel socketChannel = (SocketChannel) key.channel();
for (int i=0;i<30;i++){
String message = "message: "+i;
ByteBuffer messageBuffer = ByteBuffer.wrap(message.getBytes());
socketChannel.write(messageBuffer);
}
and on client:
while (true){
try {
int bytesreadden= channel.read(buffer);
if (bytesreadden >0){
System.out.println(new String(buffer.array(),0,buffer.position()));
buffer.clear();
}
}catch (IOException e){}
}
in my situation this 30 messages in client seems like one big message.http://i.imgur.com/hy8PsRj.png
So, what is better solution to handle this situation? Thank you!