Send()s being clumped into one packet

This is a discussion on Send()s being clumped into one packet within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I have mutiple threads that are using a function that calls Send(). I notice that in Ethereal, some of ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    224

    Send()s being clumped into one packet

    Hello,
    I have mutiple threads that are using a function that calls Send(). I notice that in Ethereal, some of the Send() calls are clumped into one packet. For example, I'll do two Send() calls with a send size of 10, but I'll notice in Ethereal, the packet size is 20. I want the send calls to be in separate packets. Is there a way to do this?

    Thanks,
    Yasir

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You are seeing the Nagle Algorithm. You can turn it off using setsockopt, however, it is recommended that you leave it on.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    I turned off Nagle's algorithm, and everything is sent separetely, but I only get back one acknowledgement. Why is this?
    Be it as it may, suppose using Nagle's algorith, I get a packet of length 110, but on the receiving side, my buffer length is 50. Will I be able to do more reads to get the rest of the data? How would I know when to stop? The messages I sent follow a certain protocol, with a header that specifies the length of the packet, and with Nagle's algorithm, my headers are no longer that useful.
    Last edited by Yasir_Malik; 05-03-2006 at 04:08 PM.

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    Ok, I ended up using Nagle's algorithm. I had to flex my pointer abilities on the receiving end, though.
    Can Nagle's algorithm only place part of a packge when doing multiple sends? For example, if I do five sends at once and the five messages are bigger than the maximum segment size but four messages are less than the MSS, will Nagle's algorithm place all of the four messages plus part of the fifth message in the same packet?

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    In a tcp connection your recieving end shouldn't be concerned with which packet data is in, it must be treated as a stream. The reason for this is that data can be split up across the network (this can offen be unnoticable while testing on a single machine or even a LAN).

    Turn off Nagle only in some situations to improve performance for example if you were sending mouse movements or other small amounts of data that you want to arrive without having to wait to see if there's any other packets to combine.

    There are two approaches. If you are using headers then you know the size of your header so call recv in a loop untill you have the header then extract the data size and call recv in a loop again untill you have the data then get the next header. The other way is with deliminaters where you keep recieving data untill you recieve a deliminater which signal the end of a packet.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Packet processing in Socket programming, please help
    By pumpkin in forum Networking/Device Communication
    Replies: 5
    Last Post: 05-28-2009, 02:33 AM
  2. Replies: 4
    Last Post: 05-05-2009, 06:35 AM
  3. dll to encrypt packet sends
    By splintter in forum C++ Programming
    Replies: 22
    Last Post: 04-20-2008, 10:00 PM
  4. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 04:25 AM
  5. Raw Packet (sorry tripple weird Post)
    By Coder87C in forum Networking/Device Communication
    Replies: 6
    Last Post: 03-04-2006, 11:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21