fix socket_write for loop