TCP Socket Flush

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nuno Magalhaes

    TCP Socket Flush

    How to do a TCP socket flush in order to get the packets to their real
    sizes (and not accumulate) like when we send a datagram UDP. When we
    send UDP it comes with the real packet size, in other words, the packet
    is sent away immediatly.

    TCP accumulates. How can we send each packet individually?

  • Jon Skeet [C# MVP]

    #2
    Re: TCP Socket Flush

    Nuno Magalhaes wrote:[color=blue]
    > How to do a TCP socket flush in order to get the packets to their real
    > sizes (and not accumulate) like when we send a datagram UDP. When we
    > send UDP it comes with the real packet size, in other words, the packet
    > is sent away immediatly.
    >
    > TCP accumulates. How can we send each packet individually?[/color]

    I believe you want to set the NoDelay socket option.

    Jon

    Comment

    • Nuno Magalhaes

      #3
      Re: TCP Socket Flush

      It works. Thanks.

      Comment

      • Nick Hounsome

        #4
        Re: TCP Socket Flush


        "Nuno Magalhaes" <nunommagalhaes @hotmail.com> wrote in message
        news:1138899546 .302487.108350@ g43g2000cwa.goo glegroups.com.. .[color=blue]
        > It works. Thanks.[/color]

        It works for your current circumstances:

        1) If your receiver gets busy it can still read more than one "packet" at
        once.
        2) The internet can break up your "packet" so that less than a full packet
        is received in one read.

        There is no way to prevent this behaviour because TCP does not support the
        concept of a "packet" therefore you should always code so as to accept TCP
        data in arbitrary chunks.

        Contrary to popular belief even UDP packets can be broken up - just try to
        send a packet that is bigger than an ethernet frame and see what happens.


        Comment

        Working...