0

I'm using Python 3 but assume Python 2 would work similarly

I want to have a python TCP socket receive exactly x_bytes.

msg = sock.recv(x_bytes)

This returns no more than x_bytes but may return less.

https://stackoverflow.com/a/1830689/10534730 suggests to use recv(x_bytes, socket.MSG_WAITALL) but notes that it only seems to work on Unix. I am on Windows.

Jonathan
  • 39
  • 1
  • 6
  • See the top voted answer then, https://stackoverflow.com/questions/1708835/python-socket-receive-incoming-packets-always-have-a-different-size/1806965#1806965, and also follow the link (ActiveState recipes should be applicable for Windows too) – tevemadar Nov 18 '20 at 23:57
  • Here is an old answer of mine: https://stackoverflow.com/a/56814032/238704 – President James K. Polk Nov 19 '20 at 02:02
  • You can't. You just have to keep calling it until you get enough bytes. – user253751 Nov 19 '20 at 16:06

0 Answers0