Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Client (this.m_socket is the web socket which you pass to the constructor of cee.ug.RemoteModel):

 

    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: Add this to the main.js file, before the serverInstance.start(); line:

 

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);

});

 

 

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

 

Response from client: {

  "myValue": 123,

  "myString": "ABC"

}

 

And this on the server side:

 

packetData: incomingPacketName:GetCustomData, incomingData: {

  "command": "getInfo",

  "data": "partId:123"

}, 

                 modelKey: Poppet_Valve.vtfx, fullModelFileName: Poppet_Valve.vtfx

  • No labels