Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event listeners not being fired on iOS #36

Closed
Tbrz423 opened this issue Oct 14, 2019 · 5 comments
Closed

Event listeners not being fired on iOS #36

Tbrz423 opened this issue Oct 14, 2019 · 5 comments

Comments

@Tbrz423
Copy link

Tbrz423 commented Oct 14, 2019

I've setup a SocketIO client in my Flutter project, and can successfully connect to a local SocketIO server. The connect and disconnect events work, and I am able to emit data to the server, however when the server emits data the client's events don't fire.

Code for client:

IO.Socket socket = IO.io('http://127.0.0.1:5000', <String, dynamic>{
   'transports': ['websocket']
 });

 socket.on('connect', (_) {
  print('connected');
  socket.emit('message', {'message': 'hello'});
 });

 socket.on('message', (data) {
   print(data);
 });

 socket.on('disconnect', (_) => print('disconnect'));

The server is written in Python using Flask-SocketIO, and I know the implementation is correct as it can communicate fine with Python and C# SocketIO programs.

Flutter version: 1.9.1+hotfix.4
socket_io_client version: ^0.9.4

I suspected this might have been a firewall problem however I was able to run a similar Python SocketIO server and send and receive messages on the same computer.
Any help is appreciated.

@jumperchen
Copy link
Member

Please try with the latest version to see if it helps.

@larsbs
Copy link

larsbs commented Feb 19, 2020

Just tried it, the issue still persists.

@jumperchen
Copy link
Member

jumperchen commented Feb 20, 2020

@larsbs I try the following example with iPhone 11 simulator on Android Studio, it works well.
Here is my env. version:

  • NodeJs Socket.io server: 2.3.0
  • Flutter 1.12.13+hotfix.7
  • Dart 2.7.0
  • socket_io_client 0.9.8

The example,

void initState() {
    super.initState();
    _socket = IO.io('http://MyIPAddress:3000', <String, dynamic>{'transports': ['websocket']});
    print('test');
    _socket.on("connect", (_) {
      print('Connected');
      _socket.emit('toServer', json.encode({'key': 'hello', 'value': 'world'}));
    });
    _socket.on("fromServer", (_) {
      print('fromServer $_');
    });
    _socket.on("connect_error", (data) => print('connect_error: ' + data));

  }

Socket.io server (both NodeJs 2.3.0 and Dart version are okay)

var http = require('http').createServer();
var io = require('socket.io')(http);

io.on('connection', (client) => {
    console.log('a user connected')

    client.on('toServer', (data) => {
        console.log('Message received --> ', data)
        client.emit('fromServer', 'fromServer -> ' + data);
    })
})

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

The result printed on Android Studio:

Performing hot restart...
Syncing files to device iPhone 11 Pro Max...
Restarted application in 1,712ms.
flutter: test
flutter: build
flutter: Connected
flutter: fromServer fromServer -> {"key":"hello","value":"world"}

@larsbs
Copy link

larsbs commented Feb 20, 2020

Confirmed to be working. I wasn't specifying the transport protocol.

@jumperchen
Copy link
Member

@Tbrz423 I try with the python server example, and the code above I post still works well on Android Studio in either iOS or Android simulator, so I close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants