walolinux
walolinux

Reputation: 551

Socket.io emit special characters

I am working in a small project which is Socketio 0.9 based. Everything is working well but I am having a small issue with special characters.

I am creating a dynamic JSON object from JavaScript in a web client which is emitted to the server:

var config = new Object();
config.name1 = 'Iñaki';
config.name2 = 'Óscar';
config.name3 = 'Alba';

var data = new Array();
data.push(config);

var myJson = new Object();
myJson.hash = hash;
myJson.serial = serial;
myJson.data = data;

iosocket.emit('config', myJson));

And in the server I am receiving end emitting it to other clients:

    socket.on('config', function (data) {
        ...
        socket.broadcast.to(myroom).emit("data", data.data);
    }

At this point, if I have any special chars like 'Iñaki' or 'Óscar' in my config JavaScript Object my data is not emitted from socketio to my clients. But if I fill in the Object with non special characters names, it works out of the box.

Why?

Note: I cannot upgrade to socketio 1.x
Note: My server.js is UTF-8 saved.

Thanks.

Upvotes: 1

Views: 1269

Answers (1)

Fredy Ugarriza
Fredy Ugarriza

Reputation: 31

I was struggling with the same problem today.

In my case the problem was that the socket.io version for server and client was not the same. I was using socket.io-client 2.0.1 and Socket.io 1.4.0 so downgrading socket.io-client version to 1.4.0 fixed the problem.

Upvotes: 1

Related Questions