'Sending to server via tcp

Data is not sent to the server although the connection is working properly, if possible, send an example of connecting to the server to send data in one stream.

class Server {
  Socket? _socket;
    
  void connectToServer() async {
    try {
      _socket = await Socket.connect('127.0.0.1', 7890);
      log('connected: ${_socket!.remoteAddress.address}:${_socket!.remotePort}');
    } catch (e) {
      log(e.toString());
    }
  }
    
  void send(temp) {
    _socket?.listen((List<int> event) {
      log(utf8.decode(event));
    });
    _socket?.add(utf8.encode(temp));
  }
}


Solution 1:[1]

Try the write function.

_socket?.write({'tes' : 'test'});
_socket?.writeln('test');

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 InFicial Infotech