connectSocket method

dynamic connectSocket(
  1. Function onConnection,
  2. String ipSocket,
  3. int port
)

connectSocket

Implementation

connectSocket(Function onConnection, String ipSocket, int port) async {
  int numDevice = 0;
  bool ok = false;
  var splitIp = ipSocket.split('.');
  while (numDevice <= 255 || ok) {
    try {
      splitIp[3] = numDevice.toString();
      ipSocket = splitIp.join(',').replaceAll(',', '.');
      _socket = await Socket.connect(ipSocket, port,
          timeout: const Duration(milliseconds: timeOutConnect));
      ok = true;
      onConnection(TypesModes.connected);
      break;
    } on Exception catch (_) {
      numDevice++;
      ok = false;
      onConnection(TypesModes.connecting);
    }
  }
  !ok ? onConnection(TypesModes.errorConnected) : onConnection(TypesModes.connected);
}