几秒钟后客户端上的套接字断开连接

时间:2018-09-20 15:26:53

标签: node.js socket.io

我的套接字代码如下所示:

let socketObject = {};


const connectSocket = (io) => {

    //listening to socket server
    io.on('connection', (socket) => {
        socketObject = socket;
        console.log('a user is connected');

        socket.on('disconnect', () => {
            console.log('a user is disconnected');
        })
    });

};


//this emits data to a particular socket channel
const emitData = (channel, data) => {
    socketObject.emit(channel, data, (info) => {
        console.log('info is ' + info);
    });
};


module.exports = {
    connectSocket,
    emitData
}

在这里,几秒钟后a user is disconnected

0 个答案:

没有答案