Is Python socket.send limited in size?

Viewed 207

I have a bytearray. I checked its size with len and it's 15.000 bytes. However, when sending it through s.send(), where s is a socket, only 6000 bytes are sent.

Is this normal ? The next call to send doesn't even send the rest.

More details : Even with splittig with 3 sendall it does not work :

s.sendall(fbytes[:5000])
s.sendall(fbytes[5000:10000])
s.sendall(fbytes[10000:])
2 Answers

Yes, this is normal. The socket buffer kept by the kernel is only so big. You can either set up a loop:

while data:
    transmitted = s.send(data)
    data = data[transmitted:]

or call s.sendall(data) which, in essence, does that for you.

If you want to receive more bytes than the limit, there should be the following code somewhere in your Python file.

client.recv(1024)

In the above example, 1024 is the number of bytes to read from the client.
If you want more bytes, you can do the following.

bytes_to_recv = 2000
client.recv(bytes_to_recv)
Related