Walters.Robert Posted October 7, 2019 Share Posted October 7, 2019 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. Link to comment
cash-metall Posted October 8, 2019 Share Posted October 8, 2019 The Socket class inherits the methods of the Stream class.https://developer.unigine.com/en/docs/2.9/api/library/common/class.stream?rlang=cpp you can use float value1 = socket->readFloat(); int value2 = socket->readInt(); Link to comment
Walters.Robert Posted October 8, 2019 Author Share Posted October 8, 2019 @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. Link to comment
fox Posted October 8, 2019 Share Posted October 8, 2019 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! Link to comment
Recommended Posts