I am writing dummy server for my project to accept request from client and return 1 or more responses back. On the dummy server side, it gets the request from client, and find the matched message to send back. Below is piece of code of writing part.
for (String line : response) {
ByteBuffer msgBuf = ByteBuffer.wrap(line.getBytes());
if (!ccc.isConnected())
ccc.connect(new InetSocketAddress("127.0.0.1", 50051));
logger.info("Capacity of msgBuf is : " + msgBuf.capacity());
ccc.write(msgBuf);
logger.info("Seding out the response : " + line);
msgBuf.rewind();
Thread.sleep(2000);
}
if sever found 2 data to send back, the ccc socket will write twice. I put Thread.sleep(2000) there, coz if I don't do this, the client side will get 2 data together. But I want the server send the data one by one.