Flutter客户端套接字如何连接到套接字服务器?

问题描述 投票:2回答:1

我想通过Flutter移动应用程序连接我的套接字服务器,但是它不起作用。我的服务器代码(Node.js):

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = process.env.PORT || 3000;

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html');
});

io.on('connection', function(socket){
  console.log("biri geldşi")
  socket.on('chat message', function(msg){
    console.log(msg)
    io.emit('chat message', msg);
  });
});

http.listen(port, function(){
  console.log('listening on *:' + port);
});

我的Flutter应用程序代码:

  import 'package:socket_io_client/socket_io_client.dart' as IO;

  main() {
  IO.Socket socket = IO.io('http://192.168.1.102:3000');
  socket.on('connection', (_) {
    print('connect');
    socket.emit('chat message', 'test');
  });
  socket.on('event', (data) => print(data));
  socket.on('disconnect', (_) => print('disconnect'));
  socket.on('fromServer', (_) => print(_));
}
javascript node.js sockets flutter dart
1个回答
-1
投票

您知道怎么做吗?我正试图做同样的事情。

热门问题
推荐问题
最新问题