rikulo / socket.io-client-dart

socket.io-client-dart: Dartlang port of socket.io-client https://github.com/socketio/socket.io-client
https://quire.io
MIT License
675 stars 184 forks source link

emit and send not working #320

Open yahyaizala opened 1 year ago

yahyaizala commented 1 year ago

Hi there, I faced an issue. I can connect socket.io server and server can send me events too. Bu in iOS and android application I can not send any message to server via emit and send functions.

import 'dart:async'; import 'dart:convert'; import 'dart:io';

import 'package:flutter/material.dart'; import 'package:meetmed/Screen/MainView.dart';

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

void main() { IO.Socket client; client = IO.io( Platform.isAndroid ? "http://10.0.2.2:8080" : "http://localhost:8080", IO.OptionBuilder() .setTransports(["websocket"]) .enableAutoConnect() .build());

client.onConnect((_) { print("connection worked on ${client.id} socket id"); client.emit("onAuth", {"data": "test data"});

int counter = 1;
Timer.periodic(Duration(milliseconds: 500), (timer) {
  Map<String, dynamic> map = Map<String, dynamic>();
  map["message"] = "Hello";

  client.emit("onAuth", map);
  client.emitWithAck("onAuth","init", ack: (data) {
    if (data == null)
      print("null onAuth");
    else
      print("not null $data");
  });

  print("sending");
  counter++;
  if (counter >= 5) {
    timer.cancel();
  }
});

});

client.on("message", (data) { print("message received ${data}"); }); client.on("me_connected", (data) { print("me connected worked ${data}"); client.emit("onAuth", {"data": "send yoy"}); }); client.on("onAuth", (data) { print("on auth message $data"); }); client.onError((data) { print("Error occured $data"); });

runApp(const MainView()); }

Os : macOS Air M1 chip socket.io version 4.6.0 (js server)

socket.client version 2.0.1 (flutter package)

arisAlexis commented 1 year ago

yes same for me, nothing works.

x3noku commented 1 year ago

Absolutely same. Neither emit, emitWithAck or send don't work. While messages from the server still can be received

movieator commented 7 months ago

Same problem here. Emit is not working

Alvish0407 commented 6 days ago

Add, {'transports': ['websocket']}

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

For more info https://github.com/rikulo/socket.io-client-dart/issues/134#issuecomment-749295262