43
« on: February 03, 2017, 04:27:05 PM »
Is TCPObject blocking? That looks like a local variable. If it's not blocking then as soon as you're out of scope, nothing will be received because the object won't exist anymore. After a bit of googling, I was able to fudge this together (I have tested):
package buildTerrain {
function buildTerrain(%pos1, %pos2)
{
%TCPI = new TCPObject(TerrainTCPObject);
%TCPI.setBinary(true);
%TCPI.connect("127.0.0.1:4878");
}
function TerrainTCPObject::onConnected(%this)
{
echo("Connected.");
}
function TerrainTCPObject::finish(%this)
{
%this.disconnect();
echo("Disconnected.");
}
function TerrainTCPObject::onBinChunk(%this, %size)
{
echo("Received new data.");
if(%this.contentLength !$= 0) {
echo("Saving data to file.");
%this.saveBufferToFile("base/server/temp/terrainData");
}
}
};
deactivatePackage("buildTerrain");
activatePackage("buildTerrain");
Send it whatever and it will save it. Now how to handle buffer size you will need to get an initial content length then you can resize the buffer using setBinarySize() and close the connection within onBinChunk() using the existing if statement with an 'else' statement. If you use setBinarySize(), you won't need to call setBinary() unless you want to go back to non-binary mode.