c++ - Socket (TCP) using recv to receive data blocking problem?
扔个三星炸死你
扔个三星炸死你 2017-06-10 09:48:28
0
2
1231

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?

扔个三星炸死你
扔个三星炸死你

reply all(2)
洪涛

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)

大家讲道理

You can use the setsockopt() function to set the timeout period

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!