如何在 Flask 中使用命名空间设置套接字?

问题描述

如何在 Flask 中使用命名空间设置套接字?

在 JS 中,我们可以像这样设置带有命名空间“connection”的套接字:

//Setting up a socket with the namespace "connection" for new sockets
io.on("connection",socket => {
    console.log("New client connected");

    //Here we listen on a new namespace called "incoming data"
    socket.on("incoming data",(data)=>{
        //Here we broadcast it out to all other sockets EXCLUDING the socket which sent us the data
       socket.broadcast.emit("outgoing data",{num: data});
    });

    //A special namespace "disconnect" for when a client disconnects
    socket.on("disconnect",() => console.log("Client disconnected"));
});

example in JS

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)