简体   繁体   English

如何使用 flutter 连接到 nodejs 服务器上的 socket.io?

[英]how to connect to socket.io on nodejs server using flutter?

I am developing a backend using node js and express framework and I will use socket.io in order to make a realtime connection between the server and the client ( flutter app ).我正在使用 node js 和 express 框架开发后端,我将使用 socket.io 在服务器和客户端之间建立实时连接( flutter 应用程序)。

I have created a socket.io configuration on the server-side code and this is the code snippet:我在服务器端代码上创建了 socket.io 配置,这是代码片段:

const server = app.listen(port);
    const io = require('socket.io')(server);



    io.on('connection' , client => {
        console.log('one connected');
    });

and on the client side:在客户端:

SocketIO socketIO;


socketIO = SocketIOManager().createSocketIO(SERVER_URL, '/');

    socketIO.init().then(
          (result) async {



            await socketIO.subscribe('connection', (){});
            await socketIO.connect();

          },
        );

the problem that I can't see one connected logged in the console of the node app.我在节点应用程序的控制台中看不到一个已连接的问题。

it doesn't throw any error on the client-side and I want to know if I am on the right way.它不会在客户端引发任何错误,我想知道我是否走对了。

Thanks,谢谢,

After searching I found that the solution was to create my server using http plugin.经过搜索,我发现解决方案是使用 http 插件创建我的服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM