Java version of server class (no memory leaks!)