casting strings to bytes before writing to socket for python3 compatibility