What is a message boundary?

15,557

Solution 1

No, message boundaries have nothing to do with destinations or ports. A "message boundary" is the separation between two messages being sent over a protocol. UDP preserves message boundaries. If you send "FOO" and then "BAR" over UDP, the other end will receive two datagrams, one containing "FOO" and the other containing "BAR".

If you send "FOO" and then "BAR" over TCP, no message boundary is preserved. The other end might get "FOO" and then "BAR". Or it might get "FOOBAR". Or it might get "F" and then "OOB" and then "AR". TCP does not make any attempt to preserve application message boundaries -- it's just a stream of bytes in each direction.

Solution 2

Message boundaries in this context is simply the start & end of the message/packet. With TCP connections, all messages/packets are combined into a continuous stream of data, whereas with UDP the messages are given to you in their original form. They will have an exact size in bytes.

Share:
15,557

Related videos on Youtube

KMC
Author by

KMC

Tutorials: WPF C# Databinding C# Programming Guide .NET Framework Data Provider for SQL Server Entity Framework LINQ-to-Entity The Layout System Resources: LifeCharts: free .NET charts FileHelper: text file helper cmdow

Updated on June 11, 2022

Comments

  • KMC
    KMC almost 2 years

    What is "message bonudaries" in the following context?

    One difference between TCP and UDP is that UDP preserves message boundaries.

    I understand the difference between TCP and UDP, but unsure about the definition of "message boundaries". Since UDP includes the destination and port information in each individual packet, could it be this that gives message a "boundary"?

  • KMC
    KMC about 12 years
    In TCP, would the stream / buffer transmit or receive in order? I wouldn't not get "BAR" before "FOO" or each byte may mixed up to something like "ORAFBO"?
  • Jonas Bötel
    Jonas Bötel about 12 years
    @KMC: Wikipedia TCP: TCP provides reliable, ordered delivery of a stream of bytes [..]
  • David Schwartz
    David Schwartz about 12 years
    @KMC It may or may not get transmitted in order on the wire (in practice it will be, but no law requires it to be), however, it will be presented in order to the receiving application.
  • torez233
    torez233 almost 3 years
    on the receiver side, how does it ensure that it has completely read the content of a request message, potentially across multiple calls of recv, without mixing the data sent from the next request. I think for HTTP the "Content-Length" can be used as a hint about how many bytes are left once all headers are read. For other application protocols built on top of TCP, like DNS or SMTP, are they using similar idea?
  • David Schwartz
    David Schwartz almost 3 years
    @hafan96 That's the job of the protocol implementation in the sender and receiver. They can use length-preceded messages, they can use boundary characters (like each message on its own line), or other mechanisms.