When python socket is reading, the (recv) server is disconnected, and there is no exception at this time. What if I catch this error state?

the (recv) server is disconnected when python socket is read, and there is no exception at this time. What if I catch this error state?

Mar.10,2021

take the TCP protocol as an example. If socket uses blocking mode to call recv () , an empty string is returned, indicating that the TCP connection has been closed normally.

sample code is as follows

-sharp sk = socket(...)
-sharp ...
while True:
    data = sk.recv(1024)
    if not data:
        break  -sharp 
    -sharp ...
Menu