If the remote side of your connection goes away, this means that the first write to the socket after the connection goes away is LOST.
To replicate, run netcat -lk 4242
Then in a python shell (instantiate your socket and connect to it. Before the first sendall, Ctrl-C your netcat server):
>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.settimeout(2)
>>> s.connect(('localhost', 4242))
>>> s.sendall('\n'.encode('utf8'))
>>> s.sendall('\n'.encode('utf8'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 32] Broken pipe
Not sure if there is a socket flag to avoid this. A hack would be to just s.sendall('\n'.encode('utf8') first before attempting to actually writing data.
If the remote side of your connection goes away, this means that the first write to the socket after the connection goes away is LOST.
To replicate, run
netcat -lk 4242Then in a python shell (instantiate your socket and connect to it. Before the first sendall, Ctrl-C your netcat server):
Not sure if there is a socket flag to avoid this. A hack would be to just
s.sendall('\n'.encode('utf8')first before attempting to actually writing data.