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

1

7

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

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.
Runge answered 15/8, 2011 at 3:33 Comment(0)
O
4

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.

Opportunist answered 15/8, 2011 at 3:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.