0

Broken Pipes & Comparison Between send() and sendall()

Hey, 1. I get this error in my program: BrokenPipeError: [Errno 32] Broken pipe How can I fix it? what does it mean? 2. what's the difference between socket.send() and socket.sendall()? Which one should I use? all i know is that sendall() is a higher level pythonic function.

20th Sep 2021, 7:38 PM
Yahel
Yahel - avatar
2 ответов
0
2. All of them send data to the socket. Send returns the number of bytes sent. Sendall continues to send data until all data has been sent and returns None. I can write something like sendall function. Maybe it will be useful. def sendall(sock, data): n = sock.send(data) if n > 0: return sendall(sock, data[n:]) return None In case of most simple network applications you should use sendall.
22nd Sep 2021, 12:51 AM
Михаил Иванов
Михаил Иванов - avatar
0
1. It could mean a socket on client side is closed. Handle the exception.
22nd Sep 2021, 1:17 AM
Михаил Иванов
Михаил Иванов - avatar