Comments (3)
@fullee
run_local
mode is not designed to be running in the multiple-thread/coroutine context.
Please use run_backend
to get the compatibility of async/await
keywords
Examples can be found in exec_backend
Brs.
from ssh-rs.
The following codes can be compiled with axum
server but I didn't try 'em out as a real WebSocket server.
async fn ws_handler(ws: WebSocketUpgrade) -> impl IntoResponse {
ws.protocols(["binary"]).on_upgrade(handle_client)
}
pub async fn handle_client(mut client: WebSocket) {
let mut ssh = ssh_rs::ssh::create_session()
.username("ubuntu")
.password("password")
.connect("127.0.0.1:22")
.unwrap()
.run_backend();
loop {
if let Some(msg) = client.recv().await {
if let Ok(msg) = msg {
match msg {
Message::Text(t) => {
println!("client sent str: {:?}", t);
// let exec = ssh_cloned.lock().unwrap().open_exec().unwrap();
let exec = ssh.open_exec().unwrap();
exec.send_command(&t).unwrap();
let vec = exec.get_result().unwrap();
if client
.send(Message::Text(String::from_utf8(vec).unwrap()))
.await
.is_err()
{
println!("client disconnected");
};
}
Message::Binary(_) => {
println!("client sent binary data");
}
Message::Ping(_) => {
println!("socket ping");
}
Message::Pong(_) => {
println!("socket pong");
}
Message::Close(_) => {
println!("client disconnected");
return;
}
}
} else {
println!("client disconnected");
return;
}
} else {
println!("client disconnected");
return;
}
}
}
from ssh-rs.
ok,i love you
from ssh-rs.
Related Issues (20)
- 是否可以在登录的时候设置StrictHostKeyChecking属性? HOT 8
- 增加任务状态的建议 HOT 1
- How to obtain SshError HOT 8
- Only captures stdout HOT 2
- add more encryption algorithms HOT 3
- Bump ssh-key crate version HOT 4
- `tracing` dependency is not new enough
- Ssh-rs panic on a thread when using in multi threading HOT 4
- Error when connecting to older ExtremeXOS switch HOT 1
- 能否支持一边读取命令执行结果一遍输出,而不是等到整个命令完全执行完毕再输出所有的结果? HOT 1
- ssh -rs crashed on Zero lenght version information HOT 4
- Use Rust std TCP set_read_TimeOut instead of a custum one ? HOT 3
- add connect_with_timeout to set connection timeout HOT 4
- Getting command exit status HOT 3
- Scp: quoting errors with spaces in dest filename HOT 5
- Scp: track progress for larger transfers HOT 2
- Scp: path-related bugs on windows HOT 1
- OpenSSH client drop-in replacement
- [email protected] request ignored HOT 1
- "Auth error" against freebsd HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ssh-rs.