use try with resources
implement tcp client, refactoring