Jump to content
  • Advertisement
Sign in to follow this  

Number Discrepency

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

Hi. I have a client that connects to a server and attempts to send the number 400 to the server, that goes well.
int Send(SOCKET socket,int _buffer )
{
    
    
    
    send( socket, reinterpret_cast< char * >( &_buffer ), sizeof( _buffer ) , 0 );
    Logger.LogInt(_buffer); // Log to make sure i sent the right number
    if (nret == SOCKET_ERROR) {
    return NETWORK_ERROR;
    }
    
    else{}
}


However, instead of 400, the server is receving 249, i checked this after multiple tests via my log file. Here is the servers recv function:
  int Recv(SOCKET socket)
  {
     char buffer[256];
     int _buffer;


     nret = recv( socket, reinterpret_cast< char * >( &_buffer ), sizeof( _buffer ) , 0 );
     
     _buffer = iShiptwo_x;
     Logger.LogInt(iShiptwo_x); // log what i recieved!
    
     if (nret == SOCKET_ERROR) {
	// Get a specific code
	// Handle accordingly
	return NETWORK_ERROR;
     } else {

     }

}


If any one has an idea on whats going on, that'd be great, thanks.

Share this post


Link to post
Share on other sites
Advertisement
Are your client and server on different operating systems ?
This might be a problem with byte ordering, some OS are big endian others are small endian.

Try using htonl(long x) to convert and integer before sending.
And ntohl(long x) to convert the integer after recieving.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Instead of "_buffer = iShiptwo_x;" maybe you mean "iShiptwo_x = _buffer;"?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!