Refactoring of TCP/SSL client sockets