1. Is it possible to receive multiple messages in one receive call?
Sender pseudo-code:
target = ("xxx.xxx.xxx.xxx", 1234)
sender = new_udp_socket()
sender.send("Hello", target)
sender.send("World", target)
Receiver pseudo-code:
receiver = new_udp_socket()
receiver.bind("", 1234)
while true
data = receiver.recvfrom(512)
print(data)
Is it possible that the receiver will receive "HelloWorld"
in one receive call instead of "Hello"
and "World"
separately?
I have been told that it is possible, but I'd like to make sure.
2. If it is possible to receive multiple messages in one receive call, how do I ensure that my code processes both messages separately?
I've been thinking about this but couldn't come up with any solution.
My first idea was that I would add a byte at the beginning of the send call stating the length of the message.
I don't believe this would be reliable either because if too much data is in the receivers buffer then the beginning (the message length) may be cut off and therefore my program would fail.
Thanks for any help!
After much research I have found an answer to my question.
One recvfrom call will only ever receive one sendto call.
Sources: