fix a logical error in reading data from socket