Answer the question
In order to leave comments, you need to log in
How to change client.id in node.js(socket.io)?
code example:
//тут какой то код...
io.sockets.on("connection", function (client)
{
//...
client.on("message", function (r)
//...
{ io.sockets.to(client.id).emit("message", b))
//тут какой то код...
Answer the question
In order to leave comments, you need to log in
client.id is a unique session ID for each server, and in theory, if the disconnect is handled incorrectly, it can be assigned to a completely different client. In general, controlling the direct relationship between socket.io client.id and the client ID in the database is not an easy task.
It's much easier to store this ID on the client (localStorage) and pass it with every message and maintain one up-to-date mapping of MySQL ID <=> client.id in server memory.
There is a well-known problem with parallel open tabs - by default browsers can keep 2-3 permanently open connections (websocket) per URL. Solved by synchronizing tabs via localStorage: html5demos.com/storage-events
Or https://groups.google.com/forum/#!topic/socket_io/... ,
orstackoverflow.com/questions/18654567/save-socket-i...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question