CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2004
    Posts
    2

    Why doesn't it work?

    What is wrong with this?

    The client initiates contact with the server and sends a single CMsg object
    When the Server receives it this happens :

    A reply of 8 messages

    Code:
    void CServerDlg::dealWithRecvdMsg(CMsg& msg)
    {
    	CMsg msg;
    	for ( int i = 0; i < 8; i++ )
    	{
    //		a different msg each time
    		SendPost(msg);
    
    //  watch what happens when the Sleep time changes
    		Sleep(1000);     
    	}
    }
    on the other side
    the client receives them :
    Code:
    void CCliSock::OnReceive(int nErrorCode)
    {
    	CSocket::OnReceive(nErrorCode);
    	m_pParentdlg->PickUpPost(m_pArchiveIn);
    }
    the messages are deserialized :
    Code:
    void CClientDlg::PickUpPost(CArchive* pArchiveIn)
    {
    	CMsg msg;
    	
    	do
    	{
    		try 
    		{
    			msg.Serialize(*pArchiveIn);
    		}
    		catch(CFileException e)
    		{
    			pArchiveIn->Abort();
    			AfxMessageBox(_T("Abort in CClientDlg.:PickupPost"));
    		}
    		
    		if (pArchiveIn == NULL)
    			break;
    
    	} while (!pArchiveIn->IsBufferEmpty());
    	
    	dealWithRecvdMsg(msg);
    }
    here the messages are taken apart and dealt with :
    Code:
    void CClientDlg::dealWithRecvdMsg(CMsg& msg)
    {
    // sort out the individual messages
    }
    If there is a 1000ms sleep time it works
    if there is a 500ms sleep time it works
    but it there is a 5ms sleep time between transmissions It Doesn't Work
    and I only am able to see the 1st and 8th message.

    What am I doing wrong?

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    [Moved thread]

  3. #3
    Join Date
    Apr 2004
    Posts
    1

    Unfortunate

    The first CMsg came in one single chunk and fired
    OnReceive() once. But it seems that by the time
    the remaining CMsgs reach the client,
    the 2nd to the last are all bunched together in one
    single chunk that fires one single OnReceive() after the first,
    So in this loop take apart the single chunk and
    deal with each CMsg before finishing with the chunk

    Code:
    void CClientDlg::PickUpPost(CArchive* pArchiveIn)
    {
    	CMsg msg;
    	
    	do
    	{
    		try 
    		{
    			msg.Serialize(*pArchiveIn);
    		}
    		catch(CFileException e)
    		{
    			pArchiveIn->Abort();
    			AfxMessageBox(_T("Abort in CClientDlg.:PickupPost"));
    		}
    
    //              this works !!!
    	        dealWithRecvdMsg(msg);
    
    	} while (!pArchiveIn->IsBufferEmpty());
    
    //      not here, this only will catch the first and last CMsg !!!!!     	
    //	dealWithRecvdMsg(msg);
    }

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    TCP/IP (i.e. sockets) guarentees delivery of packets as well as packet ordering.

    However, it is likely when using asynchronous messaging (i.e. without waiting for a response) that you can receive 2 short messages at once.

    I suggest you build up a structure to send first, and initially send the size of the structure before the actual structure.

    Then your client/server will know how much it needs to process in each block as well as if its only received a portion of a block which it needs to decode.

    Ok ?

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  5. #5
    Join Date
    Apr 2004
    Posts
    2
    .
    However, it is likely when using asynchronous messaging (i.e. without waiting for a response) that you can receive 2 short messages at once.

    I suggest you build up a structure to send first, and initially send the size of the structure before the actual structure.

    Then your client/server will know how much it needs to process in each block as well as if its only received a portion of a block which it needs to decode.
    Thanks Darwen,
    I really do use something greater than a char string in this transmission. It is the CMsg object, a serialized class.

    And I did try it at first with a structure but syntax errors chewed my leg off. So I made the CMsg class.

    With that simple line shift that dolomiten suggested it works now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured