I'm new to C# and unity. I'm trying to send a simple string to the server using Socket.IO:
socket.Emit("collision", "Surface")
It doesn't work, i get:
I tried a bunch of things, the following code works only with strings as numbers:
var dataToSend = new JSONObject();
dataToSend["colider"] = new JSONObject("2"); // this works..
socket.Emit("collision", dataToSend);
the following gives null
- third one in the image below..
var dataToSend = new JSONObject();
dataToSend["colider"] = new JSONObject("Surface");
socket.Emit("collision", dataToSend);
Thig gives empty object { }
var dataToSend = new JSONObject();
dataToSend["colider"] = new JSONObject(JsonUtility.ToJson("Surface"));
socket.Emit("collision", dataToSend);
I get:
So how can i send/emit this "Surface" string to the server? Why is it so hard, it's just a simple string .. ?! thank you:)
I found it: socket.Emit("collision", JSONObject.CreateStringObject("Surface"));
There are a bunch of more specialized functions - the API can be found inside SocketIO/JSONObject/JSONObject.cs
- for the Socket.IO library downloaded from assets store
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.