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
Add Comment