Most languages have a built-in way to handle secure sockets, such as SslStream in .NET or the ssl module in python.
SslStream
ssl