merging write_socket with write