socket.io-client-dart icon indicating copy to clipboard operation
socket.io-client-dart copied to clipboard

emit and send not working

Open yahyaizala opened this issue 2 years ago • 4 comments

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)

yahyaizala avatar Feb 14 '23 22:02 yahyaizala

yes same for me, nothing works.

arisAlexis avatar Mar 28 '23 12:03 arisAlexis

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

x3noku avatar Sep 18 '23 15:09 x3noku

Same problem here. Emit is not working

movieator avatar Mar 24 '24 18:03 movieator