Generally speaking: socket (TCP) uses recv to receive data. If there is no data in the kernel cache, it will block.
If the TCP connection is not disconnected, but the other party never sends data, will the recv function call block the program forever?
PHP中文网2017-06-10 09:50:28
Sockets are divided into two types: blocking and non-blocking. The default blocking mode can be modified to non-blocking through parameter settings;
The meaning of blocking: It is actually the buffer in the TCP/IP protocol stack.
(1) In blocking mode: when If there is no data in the buffer, then wait until data is returned;
(2) In non-blocking mode: If there is no data, a parameter will be returned immediately (for example, an exception is thrown under Python)