0

I found, that buffer size can be set this way

sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1)  # Buffer size 8192

I set only 1 byte for the test. Let's send some big amount of data:

cat file.txt | nc -l 1489

But, I'm still able to get more than 1 byte here..

while 1:
    read_ready = select.select([sock], [], [], timeout_in_seconds)
    if read_ready[0]: # we have what to read
        data = sock.recv(1000)

It looks like buffer size is enough to keep all data from file, and it is obviously not 1 byte, what we set above.

Nik Konst
  • 47
  • 1
  • 7
  • Don't mix SND and RCV direction. You are setting sending buffer and then testing how it affects receiving of data. Please read https://stackoverflow.com/a/4476788/5378816 – VPfB Apr 11 '18 at 06:24
  • I did, but same.. no effect – Nik Konst Apr 11 '18 at 08:06
  • What effect did you expect? Questions like yours should state what you have expected and what you have observed. Also, there are min and max bounds for the buffer sizes. Please read back with getsockopt the actual size to be sure. – VPfB Apr 11 '18 at 08:24
  • I expected, that buffer will be overflowed, and when I will read it, I will got only some chars. But I got real message, with no problem – Nik Konst Apr 11 '18 at 09:11
  • The buffer affects mainly the performance. It makes a difference in overhead if you can get the same data in 1 large, 10 medium or say 50 small blocks where each block is a network packet to be sent and received and then acknowledged by another network packet. – VPfB Apr 11 '18 at 09:19
  • Well, lets say my sending is "hello". if my buffer size is 1byte, and after sock.recv(1) I'm waiting some time. I shoudl gave some character (since buffer is not responding or overwritten), which is not "e". But I got all sequence right way. – Nik Konst Apr 11 '18 at 09:25
  • I found, that if buffer size less than some value, it becomes 2304 (probably os matter, I use ubuntu). If I set bigger than 1000, it becomes twice larger. – Nik Konst Apr 11 '18 at 09:30
  • TCP is a "reliable" protocol. Transmitted data are acknowledged, timeouts are handled, missing pieces are retransmitted, blocks are checksummed. Do not expect incomplete or corrupted data for whatever reason including buffer overflows. – VPfB Apr 11 '18 at 09:59

1 Answers1

0

Update the

sysctl -w net.core.rmem_max=2500000

Then set the buffer size again

yan
  • 1,382
  • 14
  • 11