Getting multiple messages on OnReceive() event?

This is a discussion on Getting multiple messages on OnReceive() event? within the Windows Programming forums, part of the Platform Specific Boards category; Hello, This is related to Not picking up some messages , but I decided to make another topic. Is an ...

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

    Getting multiple messages on OnReceive() event?

    Hello,
    This is related to Not picking up some messages, but I decided to make another topic.
    Is an OnReceive() event fired for each message received or is it fired once for a set of messages received? For example, let's say that ten messages are sent by the server and OnReceive() fires. Should I keep on doing multiple Receive()s? If so, how do I know when to stop reading (in Unix recv() blocks)?
    Or are there 10 OnReceive()s fired?

    Thanks,
    Yasir

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    I have determined that if n packets are sent to me, n OnReceive events are fired. However, even though I get three packets sent (this is verified by Ethereal), I don't get three OnReceives fired. I verified this by logging some output to a file each time OnReceive is fired. When I received three messages in three separate packets from the server, I only get two events fired. This driving me insane. Is there any reason why this would happen? Sometimes everything works fine.
    All the findings I am stating are upon application restart.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    Figured out what the problem was: you can't do two Receive()s on one OnReceive() event. MS has documented that as well. All though MS only mentions Receive(), I guess CArchive::Read() produces the same results.
    I was doing one Receive() before as well, but I would sometimes get only two events fired even though I sent three messages. The problem was that messages were being coalesced into one packet because of Nagle's algorithm. I wrote an algorithm to handle that and partial sends as well.
    This has caused me a lot of wasted time, and I hope it helps others.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Spy++ view messages posted/sent to a control, or from it?
    By hanhao in forum Windows Programming
    Replies: 2
    Last Post: 06-25-2007, 12:07 AM
  3. Sending windows messages
    By Ideswa in forum Windows Programming
    Replies: 2
    Last Post: 03-02-2006, 01:27 PM

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