Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1.17 KB

README.md

File metadata and controls

39 lines (29 loc) · 1.17 KB

Small (and of course ugly) non blocking server written from scratch, inspired by niotut tutorial but with (slightly) different threading model. Threading is similar to Netty's workers approach.

how

Because of the only thing I can do is cloning Netty (because it is cool !), bytes handling is also very similar, just look

/**
 * Perform write on {@param context}.
 */
final EventHandler handler = (context, data) -> {

    final int remaining = data.remaining();
    final byte[] rawData = new byte[remaining];
    data.get(rawData);
    final String request = new String(rawData);

    LOG.info("Received request, as string {}", request);

    data.flip();
    context.write(context, data)//
            .setCallback(isSuccess -> LOG.info("Hey ! i was called after writing data to wire !"));
};

it has to be passed to tcp server

final ServerLoop serverLoop = new ServerLoop(null, 8080, handler);
serverLoop.start();

References

http://rox-xmlrpc.sourceforge.net/niotut/