Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page shows you how to use custom commands to communicate between the web client and the CeeCloudServer using the already established WebSocket.

Client

Add this code in the client (this.m_socket is the web socket which you pass to the constructor of cee.ug.RemoteModel): 

Code Block
languagejs
    this.m_socket.on("CustomDataResponse", (data:any) => {

...


        console.log(`Response from client: ${JSON.stringify(data, null, 2)}`)

...


    });

...

 



    this.m_socket.emit("GetCustomData", {command: "getInfo", data: "partId:123"});

 

...

 Server

In the CeeCloudServer, add this to the main.js file, before the serverInstance.start(); line: 

Code Block
serverInstance.addCustomPacketHandler("GetCustomData", (packetData, callback) => {

...



    console.log(`packetData: incomingPacketName:${packetData.incomingPacketName}, 
              incomingData: ${JSON.stringify(packetData.incomingData, null, 2)},

...


              modelKey: ${packetData.modelKey}, fullModelFileName: ${packetData.fullModelFileName}`);

...

 



    const customData = { myValue: 123, myString: "ABC" };

...


    callback("CustomDataResponse", customData);

...


});

...

Running the example 

 

Executing this the code above in the client gives this output on the client side:

 

Response from client: {

  the following output:

Client side

Code Block
Response from client: {
 "myValue": 123,

...


 "myString": "ABC"

...


}

 

And this on the server side:

...

Server side

Code Block
packetData: incomingPacketName:GetCustomData, incomingData: {

...


  "command": "getInfo",

...


  "data": "partId:123"

...


}, 

...


                 modelKey: Poppet_Valve.vtfx, fullModelFileName: Poppet_Valve.vtfx