Make sure all files are closed

Should fix ResourceWarnings on Python 3.
Close the server socket when done

Fixes ResourceWarning while running tests on Python 3.3