socket.io-client-dart
socket.io-client-dart copied to clipboard
emit and send not working
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)
yes same for me, nothing works.
Absolutely same. Neither emit, emitWithAck or send don't work. While messages from the server still can be received
Same problem here. Emit is not working