Skip to content

oyvindstegard/nioserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NIOServer - non-blocking I/O server demo in Kotlin

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.

Stream protocol for message reception

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.

Getting server side messages in code

The NIOServer instance provides received messages through a concurrent bounded queue.

Building and running tests

mvn install

Running server example

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.

Motivation

It was just a fun exercise mainly to learn a bit about java.nio non-blocking I/O, the ByteBuffer and the Selector API.

About

A non-blocking I/O server demo in Kotlin

Topics

Resources

License

Stars

Watchers

Forks

Contributors