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

does not connect to a minimal socket io node js server #35

Closed
boussarilatif opened this issue Sep 28, 2019 · 1 comment
Closed

does not connect to a minimal socket io node js server #35

boussarilatif opened this issue Sep 28, 2019 · 1 comment

Comments

@boussarilatif
Copy link

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

main() {

IO.Socket socket = IO.io('http://localhost:8000');
socket.on('connect', (_) {
 print('connect');
 socket.emit('msg', 'test');
});
socket.on('event', (data) => print(data));
socket.on('disconnect', (_) => print('disconnect'));
socket.on('fromServer', (_) => print(_));

}

//node js server
const io = require("socket.io"),
server = io.listen(8000);

let sequenceNumberByClient = new Map();

server.on("connection", socket => {
console.info(Client connected [id=${socket.id}]);

sequenceNumberByClient.set(socket, 1);

socket.on("disconnect", () => {
sequenceNumberByClient.delete(socket);
console.info(Client gone [id=${socket.id}]);
});
});

@everton-e26
Copy link

maybe you need add trasport option when creating socket instance

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

worked for me

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