add support for binary and utf8 encoding in socket.write