connect method
- @internal
Connects the socket.
Implementation
@internal
void connect() async {
if (conn != null) {
return;
}
try {
connState = SocketStates.connecting;
conn = transport(endPointURL, headers);
// handle connection errors
conn!.ready.catchError(_onConnError);
connState = SocketStates.open;
_onConnOpen();
conn!.stream.timeout(Duration(milliseconds: longpollerTimeout));
conn!.stream.listen(
// incoming messages
(message) => onConnMessage(message as String),
onError: _onConnError,
onDone: () {
// communication has been closed
if (connState != SocketStates.disconnected) {
connState = SocketStates.closed;
}
_onConnClose();
},
);
} catch (e) {
/// General error handling
_onConnError(e);
}
}