简体   繁体   English

Socket.connected 返回 false 与 Flutter Socket.io_client,连接到 Node.js Socket.io 服务器

[英]Socket.connected returning false with Flutter Socket.io_client, connected to Node.js Socket.io server

I am attempting to connect my Flutter app to a Node.js server running Socket.io.我正在尝试将我的 Flutter 应用程序连接到运行 Socket.io 的 Node.js 服务器。 However, whenever I print out socket.connected , it returns false.但是,每当我打印出socket.connected时,它都会返回 false。

My Flutter Socket.io_client is version socket_io_client: ^2.0.0-beta.4-nullsafety.0 , and my Node.js socket.io version is 3.1.2.我的 Flutter Socket.io_client 版本是socket_io_client: ^2.0.0-beta.4-nullsafety.0 ,我的 Node.js Z3D7A7766E8CDEB1C1BAE2A47A1381.9Z 版本是。 That means that there is no error caused due to version incompatability.这意味着没有由于版本不兼容而导致的错误。

What can I do to make my Flutter client connect to my Node server?我该怎么做才能让我的 Flutter 客户端连接到我的节点服务器?

Here is my code to connect to the node server.这是我连接到节点服务器的代码。

  void initState() {
    
    super.initState();
    connect();
  }

  void connect(){
    print("ASDASD");
    IO.Socket socket = IO.io("https://geobus-server.ibrahimshah.repl.co/", <String, dynamic>{
      'transports':['websocket'],
      'autoConnect': true,
    });
    socket.connect();
    socket.onConnect((data) => print("Connected"));
    print(socket.connected);
    
  }

Here is my Node.js server code:这是我的 Node.js 服务器代码:

const app = express();
const http = require("http");
const server = http.createServer(app);
var io = require('socket.io')(server);

app.get('/', (req, res) => {
  res.send('Hello Express app!')
});


app.get('/questions', (req, res)=>{
  console.log(req.url);
  

})

io.on('connection', (socket) => {
    
    console.log("User connected")
    
});

app.listen(3000, () => {
  console.log('server started');
});

My output: false我的 output: false

This is absolutely disgusting.这绝对令人作呕。 How dare you disrespect elevated buttons你怎么敢不尊重高架按钮

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

相关问题 Flutter socket.io 客户端未通过 https 与 node.js socket.io 服务器连接 - Flutter socket.io client not connecting with node.js socket.io server via https 在socket.io和node.js中获取当前连接的用户名 - Get the current connected username in socket.io and node.js [Socket.io/Node.js]Retrieving连接用户到客户端的列表 - [Socket.io/Node.js]Retrieving list of connected users to the client Flask socket.IO 服务器上的 Node.js Socket.io 客户端 - Node.js Socket.io client on Flask socket.IO server 我可以在 node.js 的 socket.io 服务器内创建一个虚拟的 socket.io 客户端吗 - Can I create a dummy socket.io client inside the socket.io server in node.js Socket.io连接始终为假 - Socket.io connected always false 套接字 io 服务器已连接 = true,但客户端已连接 = false - socket io server connected = true, but client connected = false Node.js-在Unix套接字上侦听并将数据传输到连接的Websocket(socket.io)客户端 - Node.js - listen on unix socket and transfer data to connected websocket (socket.io) clients 使用socket.io和node.js刷新或断开连接后获取套接字(已连接用户)的先前数据 - get previous data of socket(connected user) after refresh or disconnect using socket.io and node.js Node.js socket.io-服务器上看不到客户端发出 - Node.js socket.io - client emit not seen on server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM