Use NIO-like system

Rewrite of most code, one thread for all connections rather than one
thread per client.