|
-
April 13th, 2004, 02:30 AM
#1
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?
-
April 13th, 2004, 03:15 AM
#2
-
April 16th, 2004, 03:41 AM
#3
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);
}
-
April 16th, 2004, 07:17 PM
#4
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.
-
April 18th, 2004, 06:26 AM
#5
.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|