0

Say we have:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
data = s.recv(1024)

what if we receive messages, but the last message is not 1024 bytes. Will we still receive it or will we wait forever? How to receive the last message if it doesn't fill up a buffer or what not?

In Node.js, streams have "flush" behavior, where flush is called internally (not sure when), looks like this: https://github.com/ORESoftware/json-parser/blob/master/src/index.ts

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

1 Answers1

0
It is not 1024

Can mean a lot of things, it can mean:

  • It's smaller than 1024 bytes: you will receive the partial data anyway this time, and if there is other things to be received it will come when you do another recv(..)
  • It's bigger than 1024 bytes: you will receive 1024 bytes of the data coming, the rest is buffered waiting for another trigger to recv(..)
  • There is no receive data: recv(..) will wait until there is a recv data, can be changed by setting a timeout
denis_lor
  • 6,212
  • 4
  • 31
  • 55