start method
Starts the client and establishes a connection to the CLI server.
Implementation
Future<void> start() async {
if (_connectionState == ConnectionState.connected) return;
_setConnectionState(ConnectionState.connecting);
try {
// Start transport (spawns process or connects socket)
await _startTransport();
// Create JSON-RPC connection over transport
_connection = JsonRpcConnection(_transport!, log: options.log);
_connection!.onClose = _handleConnectionClose;
_connection!.onError = (error) {
options.log?.call('Transport error: $error');
onError?.call(error);
};
// Register server→client handlers
_registerHandlers();
// Verify protocol compatibility
await _verifyProtocol();
_setConnectionState(ConnectionState.connected);
} catch (e) {
_setConnectionState(ConnectionState.error);
rethrow;
}
}