Urgent question
by Ivan · in Torque Game Engine · 06/22/2006 (3:18 pm) · 2 replies
Hi all,
I have an urgent question, which should be easy to answer for any experienced tnl user but is not very clear to me. I have the following RPC code, which is called by a client and is executed on the server side.
TNL_IMPLEMENT_RPC(GameConnection, rpcMessageClientToServer, (TNL::ByteBufferPtr data), (data), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0)
{
printf("Message arrived: \n");
ClientPacket* cPacket = (ClientPacket*) data->getBuffer();
//here server should get the info somehow, not sure how
}
Several clients connect to the server and each of them send information(cPacket) to the server, which has to be collected and later broadcast back to each of the connected clients. However, after the execution of the RPC code, the data(cPacket) goes out of scope. How can I copy it to some buffer on the server before this?
Thanks a lot. Any feedback will be greatly appreciated.
I have an urgent question, which should be easy to answer for any experienced tnl user but is not very clear to me. I have the following RPC code, which is called by a client and is executed on the server side.
TNL_IMPLEMENT_RPC(GameConnection, rpcMessageClientToServer, (TNL::ByteBufferPtr data), (data), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0)
{
printf("Message arrived: \n");
ClientPacket* cPacket = (ClientPacket*) data->getBuffer();
//here server should get the info somehow, not sure how
}
Several clients connect to the server and each of them send information(cPacket) to the server, which has to be collected and later broadcast back to each of the connected clients. However, after the execution of the RPC code, the data(cPacket) goes out of scope. How can I copy it to some buffer on the server before this?
Thanks a lot. Any feedback will be greatly appreciated.
Torque Owner Shyam "Doggan" Guthikonda
To send the data back to your clients, you will need another RPC method (RPCDirServerToClient) which your server will call, passing in the data as a parameter.
Or if you wish to dispatch the data immediately, you can call the toClient RPC from within the above RPC. i.e:
TNL_IMPLEMENT_RPC(GameConnection, rpcMessageClientToServer, (TNL::ByteBufferPtr data), (data), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0) { printf("Message arrived: \n"); ClientPacket* cPacket = (ClientPacket*) data->getBuffer(); // loop through each connection (this->getNetInterface()->getConnectionList() I believe is the call) rpcMessageServerToClient(/* pass in data here */); }Hope that helps.