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

The library cannot switch between long polling and websocket #32

Closed
lopezchr opened this issue Aug 20, 2019 · 3 comments
Closed

The library cannot switch between long polling and websocket #32

lopezchr opened this issue Aug 20, 2019 · 3 comments

Comments

@lopezchr
Copy link

The library only works when you use transporting over websocket. By default the library send the connection request over http (long polling) and you can see it on the access log of the server but never switch to websocket.

We are using socket io version 2.0.4 on our server.

172.31.3.14 - - [20/Aug/2019:08:12:06 -0500] "GET /socket.io/?EIO=3&transport=polling&t=Mol9v3G&sid=c40FSVz-gs98xm1iAALE HTTP/1.1" 200 3 "http://stagingiris.1doc3.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "201.217.201.157"

@jumperchen
Copy link
Member

It works to me.
socket.io 2.0.4 version NodeJS

Screen Shot 2019-08-21 at 10 42 10 AM

Server code

const io = require('socket.io')(3000);
io.origins('*:*');
io.on('connection', function (socket) {
    socket.on('msg', (data) => {
        console.log('data from default => ' + data);
      socket.emit('fromServer', data);
    });
});

Socket.io-client-dart

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

main() {
  IO.Socket socket = IO.io('http://localhost:3000');
  socket.on('connect', (_) {
    print('connect');
    socket.emit('msg', 'init');
    int count = 0;
    new Timer.periodic(const Duration(seconds: 1), (Timer countDownTimer) {
      socket.emit('msg', count++);
    });
  });
  socket.on('fromServer', (_) => print(_));
}

@lopezchr
Copy link
Author

lopezchr commented Aug 22, 2019

We are working on a Flutter app... maybe it is not supported??

@jumperchen
Copy link
Member

jumperchen commented Aug 23, 2019

Flutter? it's not browser based, you can only use dart:io library with websocket transports, which is already mentioned here. https://github.com/rikulo/socket.io-client-dart/blob/master/test/io_client.dart

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

2 participants