connect method
void
connect(
- Uri uri,
- VoidCallback onConnected,
- StringCallback onError, {
- int timeoutSeconds = 15,
- 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);
}
});
}
}