Data available on socket?

J

Jan Danielsson

Hello all,

How do I find out if a blocking socket has data available [for
reading] on it?

I assume I could do something like this:

tmp = self.read(1, socket.MSG_PEEK)
if len(tmp) > 0:
# Data available

But is there a better way? A call which specifically checks if data
is available?
 
N

Nicolas

Jan Danielsson a écrit :
Hello all,

How do I find out if a blocking socket has data available [for
reading] on it?

I assume I could do something like this:

tmp = self.read(1, socket.MSG_PEEK)
if len(tmp) > 0:
# Data available

But is there a better way? A call which specifically checks if data
is available?

Hello,

You might want to use select.select.
See http://effbot.org/librarybook/select.htm for an example with sockets.

Nicolas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,310
Members
47,976
Latest member
SheriBolli

Latest Threads

Top