Replace close in finally with `with-open`

Close server socket and conneciton sockets using with-open instead of
calling .close in the finally block of a try statement.