• Advertisement
Sign in to follow this  

Number Discrepency

This topic is 4247 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
Why are you sending sizof(_buffer) + 1, but receiving sizeof(_buffer)?

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Why are you sending sizof(_buffer) + 1, but receiving sizeof(_buffer)?


Changed that and i still have the same problem.

Share this post


Link to post
Share on other sites
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
Quote:
Original post by Anonymous Poster
Instead of "_buffer = iShiptwo_x;" maybe you mean "iShiptwo_x = _buffer;"?


That fixed it, thanks.

Share this post


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

  • Advertisement