"The remote end closing the connection" is detected by getting EOF on a read. So to detect that you actually have to read everything the remote end sends first... Thus your requirements of not reading anything and detecting the remote end closing the connection are not compatible.