Update encoding on socket.write

Make socket.write use same encoding as socket.setEncoding.