Add optional encoding to socket library.