We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm following the forward_local.dart example, but I keep getting the following error no matter what I do.
StateError (Bad state: Stream was already listened to) #0 _RawServerSocket.listen (dart:io-patch/socket_patch.dart:1770:7) #1 new _ForwardingStreamSubscription (dart:async/stream_pipe.dart:114:10) #2 _ForwardingStream._createSubscription (dart:async/stream_pipe.dart:86:16) #3 _ForwardingStream.listen (dart:async/stream_pipe.dart:81:12) #4 _ServerSocket.listen (dart:io-patch/socket_patch.dart:2053:71) #5 _StreamIterator._initializeOrDone (dart:async/stream_impl.dart:942:33) #6 _StreamIterator.moveNext (dart:async/stream_impl.dart:918:12) #7 _MyHomePageState.sshConnect (package:vnc/main.dart) <asynchronous suspension>
Here is a snippet of my code.
int port = 0; SSHClient? _client; SSHSocket? _socket; ServerSocket? _serverSocket; bool authenticated = false; bool forwarded = false; bool connect = false; sshConnect(String targetIp) async { bool result = false; Object? exception; try { _socket = await SSHSocket.connect(targetIp, 22); _client = SSHClient(_socket!, username: SSH_USER, onPasswordRequest: () => SSH_PASSWORD, onAuthenticated: () => setState(() => authenticated = true)); await _client!.authenticated; _serverSocket = await ServerSocket.bind(LOCALHOST, port); print('Listening on ${_serverSocket!.address.address}:${_serverSocket!.port}'); port = _serverSocket!.port; await for (final socket in _serverSocket!) { final forward = await _client!.forwardLocal("locahost", 5900, localHost: LOCALHOST, localPort: port); forward.stream.cast<List<int>>().pipe(socket); socket.cast<List<int>>().pipe(forward.sink); } result = true; } catch (e) { await _serverSocket!.close(); _client!.close(); await _client!.done; _socket!.close(); await _socket!.done; result = false; exception = e; } setState(() { if (result) { forwarded = true; } else { connect = false; authenticated = false; forwarded = false; ScaffoldMessenger.of(context).showSnackBar( SnackBar( duration: const Duration(seconds: 30), content: Text('Error: $exception'), ), ); } }); } @override void dispose() { if (_client?.isClosed ?? false) _client!.close(); if (_serverSocket != null) _serverSocket!.close(); if (_socket != null) _socket!.close(); super.dispose(); }
The text was updated successfully, but these errors were encountered:
I'm running the code as a Windows app, and I have the dartssh2 2.9.1-pre package.
dartssh2 2.9.1-pre
Sorry, something went wrong.
A summarized version of the relevant code would be this.
var _socket = await SSHSocket.connect(TARGET_IP, 22); var _client = SSHClient(_socket, username: SSH_USER, onPasswordRequest: () => SSH_PASSWORD); await _client.authenticated; var _serverSocket = await ServerSocket.bind(LOCALHOST, 0); print('Listening on ${_serverSocket.address.address}:${_serverSocket.port}'); await for (final socket in _serverSocket) { final forward = await _client!.forwardLocal("locahost", 5900, localHost: LOCALHOST, localPort: _serverSocket.port); forward.stream.cast<List<int>>().pipe(socket); socket.cast<List<int>>().pipe(forward.sink); }
No branches or pull requests
I'm following the forward_local.dart example, but I keep getting the following error no matter what I do.
Here is a snippet of my code.
The text was updated successfully, but these errors were encountered: