Archived

This topic is now archived and is closed to further replies.

logout

Cant get my packet send/recv func to work

Recommended Posts

logout    122
This is from my socket wrapper :
int MySocket::SendPacket(char *pPacket, size_t iSize)
{
	int iSent = 0;

	while(iSent < iSize)
	{
		iSize += Send( ( pPacket + iSent ) , iSize-iSent );

	}
	SUCC;
}

int MySocket::RecvPacket(char *szBuff, size_t iSize)
{
	int iRecv, i;
	int iLen = sizeof(paHead);

	iRecv = i = 0;
	while(iRecv < iLen)
	{
		iRecv =+ Recv( &buffer[iRecv] , iLen-iRecv );
	}

	paHead head;
	memcpy(&head, buffer, iLen );
	
	head.iSize = iLen;
	while(iRecv < iLen)
	{
		iRecv =+ Recv( &buffer[iRecv] , iLen-iRecv );
	}

	memcpy(szBuff, buffer, iSize);
	SUCC;
}
 
What is wrong with it ? *i know 100% that send and recv works ok ! *

Share this post


Link to post
Share on other sites
johnnie2    122
So you receive the packet header, set its size to the length you've received, and then proceed to enter a while loop with the condition (iRecv < iLen). The problem with this approach is that iRecv already equals iLen because the same condition is used in the first loop. When you exit the first loop, iRecv = iLen and the second loop falls through.

You probably wanted to do


iLen = head.iSize;


to set the number of bytes to be received to the size of the incoming data, but switched around the assignment.

RapscallionGL - arriving soon.

[edited by - johnnie2 on January 28, 2003 1:15:56 PM]

Share this post


Link to post
Share on other sites
MattB    122
This looks like a problem too:

iSize += Send( ( pPacket + iSent ) , iSize-iSent );


I think you probably meant to type this:

iSent += Send( ( pPacket + iSent ) , iSize-iSent );

Share this post


Link to post
Share on other sites