Reimplemented TCP and TLS connection to use a common class.