[英]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.