connectSocket method
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);
}