connect method

  1. @override
void connect(
  1. Uri uri,
  2. VoidCallback onConnected,
  3. StringCallback onError, {
  4. int timeoutSeconds = 15,
  5. bool ignoreBadCert = false,
})
override

Connects the socket to uri then invokes onConnected or onError.

Implementation

@override
void connect(Uri uri, VoidCallback onConnected, StringCallback onError,
    {int timeoutSeconds = 15, bool ignoreBadCert = false}) {
  assert(!connecting);
  connecting = true;
  if (socket != null) {
    if (socket is SocketAdaptor) {
      (socket as SocketAdaptor).impl.connect(
          uri, () => connectSucceeded(onConnected), onError,
          timeoutSeconds: timeoutSeconds, ignoreBadCert: ignoreBadCert);
    } else {
      throw FormatException();
    }
  } else {
    Socket.connect(uri.host, uri.port,
            timeout: Duration(seconds: timeoutSeconds))
        .then((Socket x) {
      if (x == null) {
        onError(null);
      } else {
        socket = x;
        connectSucceeded(onConnected);
      }
    });
  }
}