Jump to content
  • Advertisement

Archived

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

CoMaNdore

What is wrong with my PacketRecv() function ?

This topic is 5667 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


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

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

	memcpy(szBuff, buffer, iRecv);

	SUCC; // a macro for returing

}
  

Share this post


Link to post
Share on other sites
Advertisement
quote:
What is wrong with my PacketRecv() function ?
I think you are the one to tell, and we shall answer why it is wrong. You do not say anything about the problem; crash? nothing recieved? hangs? what?

Some reading: http://www.tuxedo.org/~esr/faqs/smart-questions.html

EDIT: Something weird is going on with that link
EDIT: Google's cached one is better




[edited by - CWizard on February 9, 2003 11:54:38 AM]

Share this post


Link to post
Share on other sites
arg the forums f up; i had written a long new post ...

anyway ill make it short this time :

it hangs in the first loop for some strange reason.
and sometimes i get a 10054 error ...

and somethimes it works ... it apears to be random ...

Share this post


Link to post
Share on other sites

  
while(iRecv < iLen)
{

iRecv += Recv( &buffer[iRecv] , iLen-iRecv );

}


Imagine what happens when Recv returns -1 (error, probably going to be WSAEWOULDBLOCK).

Try something like:


  
while (iRecv < iLen)
{
int Recieved = Recv( &buffer[iRecv] , iLen-iRecv );
if (Recieved == -1)
{
if (WSAGetLastError() != WSAEWOULDBLOCK)
{
// fatal error (socket not ready etc)

return;
}
}
else if (Recieved == 0)
{
// other end terminated the connection

return;
}
else
{
iRecv += Recieved;
}
}


Alan

Share this post


Link to post
Share on other sites
Error: 10054:

n existing connection was forcibly closed by the remote host.



Given that, I bet you it deals with the server closing the socket and you''re trying to recv data on a closed socket.

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!