public static class EchoServer extends SessionTask {
@Override
public void execute() throws Pausable, Exception {
ByteBuffer buf = ByteBuffer.allocate(100);
EndPoint ep = getEndPoint();
while (true) {
buf.clear();
buf = ep.fillMessage(buf, 4, /*lengthIncludesItself*/ false);
buf.flip();
int strlen = buf.getInt();
String s= new String(buf.array(), 4, strlen);
//System.out.println ("Rcvd: " + s);
if (!s.startsWith("Iteration #")) {
ep.close();
break;
}
buf.position(0); // reset read pos
ep.write(buf); // echo.
if (s.endsWith("DONE")) {
ep.close();
break;
}
}
}