Complete rewrite of server and client connection handlers.