Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to know how much data is available in a Python socket to receive?

I have figured out that I must use ioctl. There are similar questions here:

  • How to tell how much data is in a Socket's send buffer
  • Determing the number of bytes ready to be recv()'d

My questions are:

  1. What is an equivalent to FIONREAD in Python? How do I call sock.ioctl() to obtain the amount of bytes available?
  2. What if I am using Python 2.5 on Windows? socket.ioctl is new in version 2.6.
like image 572
utapyngo Avatar asked Aug 15 '11 03:08

utapyngo


1 Answers

As there is no portable way of doing this (and often the answer is wrong), there isn't a built-in way of asking for it.

If you use non-blocking sockets, simply read as much data as possible, and only data which is present will be returned.

like image 120
Yann Ramin Avatar answered Oct 04 '22 12:10

Yann Ramin