Game Development Community

Send information to client inside the engine

by Ingo Seidel · in Torque Game Engine · 07/09/2008 (5:42 am) · 4 replies

Hi,

I am looking for a way to transmit information from the Torque server to the Torque client inside the engine, i.e. using C++ code rather than using Torque script.

As far I have seen there are two ways how this can be achieved: via the packUpdate and unpackUpdate methods or via the writePacketData and readPacketData.

In the first case (if I understood it correctly), the data is packed into a bitstream via the packUpdate methods, the mask bits of the respective update mask are set and the data is retrieved on the client via unpackUpdate. If I have a more complex structure, like an object, the client needs to instantiate a new object of the received type and can "fill" the object with object->unpackUpdate. The only problem with this approach is that it happens asynchronous and I do not know when the data will be available on the client. Furthermore the data is transmitted to all clients, right?

How does the second approach work? I did not find much documentation about it and the source code also does not help me. The main problem I am having is how to trigger the sending of the data. I am on the server and want to send information to a certain client. Do I call writePacketData on the players object and pass in the client's gameconnection as parameter? What do I have to pass in as bitstream? Do I need to create a new bitstream? In the players overwritten writePacketData method, I pack the data into the bitstream and retrieve it in an overwitten readPacketData, right? Upon reading the data in the readPacketData method I trigger certain actions on the client. The update on the client will be instantaneous, right?
Is my reasoning correct or did I get some of the concepts wrong?

thanks,

hubertus

#1
07/09/2008 (8:50 am)
I'm not really answering your final question, but regarding your original intent, I would just search for the function "commandToClient" and do what it does. I don't have source code in front of me here at work but I believe that is a C++ Console function so you could either call it directly or copy the code.
#2
07/09/2008 (10:28 am)
WritePacketData/readPacketData is only used to send data ( network updates ) from the server to a client's control object ( eg. a Player ). It is not a general purpose way to send data, it is very specific.

What exactly are you trying to send from server to client?
#3
07/10/2008 (12:39 am)
Well, I am trying to send differenct kinds of data like product data. The client request information for a certain product, the server fetches this information from an external source and then passes it to the client where it is visualized for this client. Thus, the information is specific for every client and should only be sent to this client (not possible with packUpdate/unpackUpdate?). As the data format can get a bit complex, I do not want to send it via commandToClient or script methods and would like to pass it to the client inside the engine code. The reception of the data on the client should then trigger certain actions in the script code that will update the user interface.
#4
07/10/2008 (9:49 am)
Ok then it sounds like you should derive a new NetEvent. I would look at the NetEvent.h file which has some good comments. And also at ConsoleFunction( "commandToClient" ... ). It internally is using a child class of NetEvent to store/pass the string data and then pass it to the specified script function on the client end. So you can use that (and NetEvent.h) as a template for how to make your own NetEvent.