A single threaded server using non-blocking I/O that can receive UTF-8-encoded string messages. Implemented using java.nio in Kotlin and serves as demo/example code.
Variable length UTF-8 encoded messages, up to a max receive buffer size each,
with end message marker byte (0x00). Server does not explicitly
acknowledge messages at application layer.
The NIOServer instance provides received messages through a
concurrent bounded queue.
mvn install
Fire up server on localhost, port 9999:
./run-server.sh 9999
(This script runs the main function of class MainKt by executing jar.)
In some other terminal, send the server messages consisting of the file names in your home directory:
ls -1 $HOME|tr \\n \\0|nc -w1 localhost 9999
(Each message must be ended by a null byte.)
Now check server log.
It was just a fun exercise mainly to learn a bit about java.nio non-blocking
I/O, the ByteBuffer and the Selector API.