You actually need to emit an event instead:
socket.emit('yourEvent', myObject);
If you use .send()
, you are simply sending the string representation of your object, which is where the problem is occurring. Note that you can use .send()
, but you would have to JSON-encode the object first, and decode it on reception.
Unless you have a specific reason, it's best to use the standard Socket.IO .emit()
method, as it does all of this for you. That's what it is there for.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…