Petr Skocik
Petr Skocik

Reputation: 60143

Python (UNIX) sockets -- read all data

How do I read all data from a python socket? There doesn't seem to be a "sendall" (like Socket#read in ruby) counterpart for reading and concatenating buffers seem fairly low-level for a what's supposed to be a higher level language. If I do have to resort to that (concatenating buffers that is), is there an optimal buffer size I should choose assuming that I'm dealing with UNIX sockets?

Upvotes: 1

Views: 806

Answers (1)

pilcrow
pilcrow

Reputation: 58731

The higher level of abstraction you want is in io, which can be fitted atop a socket with makefile:

s = socket.socket(...)
...
all_data = s.makefile().read(-1)  # or, equivalently, readall()
s.close()

Upvotes: 2

Related Questions