izac
izac

Reputation: 89

How to call socket.io custom server event?

I am learning socket.io and trying to create my chat. I have created a custom server event like this:

io.sockets.on("session:reload",function(sid){

var clients = io.sockets.clients();
console.log("123456");
clients.forEach(function(client){
    if(client.socket.session.id != sid) return;
    loadSession(sid,function(err,session){
        if(err){
            client.emit("error","server error");
            client.disconnect();
            return;
        }

        if(!session){
            client.emit("error","handshake unauth");
            client.disconnect();
            return;
        }
        client.socket.session = session;
    });
});
});

How can I call this from the server side?

io.sokets.$emit("session:reload",sid);

dosnt work in the new version of socket.io.

Upvotes: 0

Views: 1051

Answers (1)

user2420249
user2420249

Reputation: 248

try this

this is function on soket.js

io.on("sessreload",function(sid){
//some code
});

this is call this function

io.sockets._events.sessreload(sid);

Upvotes: 1

Related Questions