onkelv onkelv - 9 months ago 49
C# Question

Emitted jsonmessage from Unity to nodejs using Unity-socketio-websocketsharp can not be parsed

I try to send a json message using the emit method from the

unitysocketio-websocketsharp
library but the received message can not be parsed.

socket.Emit("data", "{\"name\":\"data\",\"args\":[{\"name\":\"testvariable1\",\"value\":\"-63\"}]}");


The connection can be build up and I can also receive messages from
nodejs
.

The debug output from nodejs looks like this where the [args] argument stays empty:

"name":"testvariable1","value":-63
debug - websocket writing 5:::{"name":"data","args":[{}]}

Answer Source

So i got it working not with the emit method but with the send method:

EventMessage evm = new EventMessage();
evm.Event = "data";
evm.MessageText = "{\"name\":\"data\",\"args\":[{\"name\":\"testvariable1\",\"value\": -63}]}";
socket.Send(evm);