Thread: Not pcking up some messages

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

    Not picking up some messages

    Hi,
    I am using the CSocketFile class along with CArchive. The problem that I am having is that messages are being sent to me (I checked with Ethereal about this), but I am apparently not picking up some messages. For example, I'll get the first message sent to me, but not any subsequent messages. I've seen topics on other boards about this scenario, and their solution is to do only one read, which isn't applicable in my scenario, because I want to first read in a header that has the message length, and based on that read more data. The header and data are sent as one packet, like a TCP packet. I have a onReceive function:
    Code:
    void A::OnReceive(int nErrorCode)  // A is derived from CSocket
    {
    	// TODO: Add your specialized code here and/or call the base class	
    	ReadMessage(ar_read);
    }
    And here is my ReadMessage code:
    Code:
    void B::ReadMessage(CArchive &ar)
    {
    	uchar header[4];
    	uchar buf[100]
    
    	if(!ar.IsLoading())
    	{
    		ar.Read(header, 4);
    		ar.Read(buf, header[1]); // header[1] is the length
    	}
    }
    My program isn't crashing. Any idea why my messages are not being picked up?

    Thanks.
    Last edited by Yasir_Malik; 04-21-2006 at 04:18 PM.

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    I want to add this does not happen all the time. But after getting many messages, I do not get any subsequent messages.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    I changed the ReadMessage() function, but still no luck:
    Code:
    void B::ReadMessage(CArchive &ar)
    {  
            uchar header[4];
            uchar buf[100]
    
    	if(ar.IsLoading())
    	{
    		do
    		{
    			ar.Read(header, 4); 
    			ar.Read(buf, header[1]); // header[1] is the length
            	} while(!ar->IsBufferEmpty());
    	}
    }
    Last edited by Yasir_Malik; 04-22-2006 at 06:36 AM.

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    Instead of treating the data as a stream, I treated the data coming in as a buffer, and everything appears to work fine; I did a Receive() call in the OnReceive function. I'm not convinced that this actually works. Any idea why treating the socket data as a block of data would work? When I was testing with another PC program everything worked fine, but when I tested with the actual hardware, I had these problems.
    However, in the code that sends the data to the server, I treat the message as a stream even though I do only one Write() call.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Messages Between Different Architectures
    By Cell in forum Linux Programming
    Replies: 5
    Last Post: 05-07-2009, 03:40 AM
  2. Spy++ view messages posted/sent to a control, or from it?
    By hanhao in forum Windows Programming
    Replies: 2
    Last Post: 06-24-2007, 11:07 PM
  3. Sending windows messages
    By Ideswa in forum Windows Programming
    Replies: 2
    Last Post: 03-02-2006, 01:27 PM
  4. Intercepting messages
    By ScriptBlue in forum Windows Programming
    Replies: 2
    Last Post: 06-23-2005, 12:10 AM