connect method

dynamic connect()

Implementation

connect() async {
  try {
    _socket = WebSocket(hostAddress);
    _socket.onOpen.listen((e) {
      onOpen.call();
    });

    _socket.onMessage.listen((e) {
      onMessage.call(e.data);
    });

    _socket.onClose.listen((e) {
      onClose.call(e.code ?? 0, e.reason ?? "Closed for unknown reason");
    });
  } catch (e) {
    onClose.call(500, e.toString());
  }
}