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

'transports': ['polling','websocket'] cant work #41

Closed
HnLong opened this issue Nov 13, 2019 · 2 comments
Closed

'transports': ['polling','websocket'] cant work #41

HnLong opened this issue Nov 13, 2019 · 2 comments

Comments

@HnLong
Copy link

HnLong commented Nov 13, 2019

Hi guys:
in my client as below:

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

main() {
IO.Socket socket = IO.io('http://127.0.0.1:8090/xy', <String, dynamic>{
'transports': ['polling','websocket'],
'extraHeaders': {'foo': 'bar'}
});
socket.on('connect', () {
print('socket_io_client===>connect http://127.0.0.1:8090/xy');
socket.emit('msg', 'init');
int count = 0;
new Timer.periodic(const Duration(seconds: 20), (Timer countDownTimer) {
socket.emit('msg', count++);
});
});
socket.on('event', (data) => print(data));
socket.on('disconnect', (
) => print('disconnect http://127.0.0.1:8090/xy'));
socket.on('fromServer', () => print());
}

pubspec.yaml
#socketIO
socket_io_common: ^0.9.0+5
socket_io_client:
git:
url: https://github.com/rikulo/socket.io-client-dart

and my socket server version is "socket.io": "2.0.4"(also try with "2.3.0") on the nodejs server.
now issue: the client cant conn to the server. but if transports replace with 'transports': ['websocket'],it work ok.so how to fix it in my project? thx very much!

@jumperchen
Copy link
Member

jumperchen commented Nov 13, 2019

Are you using it in Flutter env.? if so, there is no dart:html api available in Flutter, so it can only work with websocket transports in either dart:html (for Web) or dart:io(for Flutter).

@HnLong
Copy link
Author

HnLong commented Nov 13, 2019

  sure in Flutter env. yeh the README.md has explain that,i was careless.thanks chen!

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

No branches or pull requests

2 participants