Jump to content
  • Advertisement

Archived

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

logout

Cant get my packet send/recv func to work

This topic is 5651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!