Jump to content

Socket class set received data to new variable


photo

Recommended Posts

Posted

I've been following the socket instructions from: https://developer.unigine.com/en/docs/2.9/api/library/networking/class.socket?rlang=cpp 

 

The packets send and receive as expected.  Now instead of having the receiving computer log the value to a message I instead want to set a variable to the received value.  Unfortunately I haven't had any success writing my own .get() method.  Any suggestions or comments are greatly appreciated.  Ultimately the data I want to pass between machines are integers and floats.  Thanks.

Posted

@cash-metall

 

I was using the following in my get float method: 

Log::message("The float value is: (%f)\n",temp_blob->readFloat());

return(temp_blob->readFloat());

 

This would return the following:

"The float value is: 81.59....."

but the returned value would be 0.00....

 

I changed my code to:

float blobFloat = temp_blob->getFloat();

Log::message("The float value is: (%f)\n",bloatFloat);

return(blobFloat)

 

Which returns:

"The float value is: 81.59...."

and a returned value of 81.59....

 

I assume that in my first try when I called temp_blob->readFloat() for the second time the code had moved on to the next line of the blob which contained nothing so it passed in a zero.

 

Posted

Hi Robert, 

27 minutes ago, Walters.Robert said:

I assume that in my first try when I called temp_blob->readFloat() for the second time the code had moved on to the next line of the blob which contained nothing so it passed in a zero.

Yes, this was the cause - reading from a blob (stream) changes the current position at which the next reading operation will be performed.

Thanks!

×
×
  • Create New...