Python - Wait for TCP ack before sending next data

In usual case, it is not likely you need to control how socket send message, and most of the time, it is OK to send stream of data without waiting for acknowledgement for receiver. 

However, in some rare case, you may want to wait for TCP ack'ed before sending the next data out to destination. You could use fcntl.ioctl (https://docs.python.org/3/library/fcntl.html) to perform this requirement. 

In sockio.h (https://github.com/torvalds/linux/blob/master/include/uapi/linux/sockios.h), it define


We can use the above SIOCOUTQ to queue the file descriptor and get the result. If the result is not zero, it means there are bytes unsent in the queue.

Below is a sample code



Comments

Popular Posts