You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Usually when proxying a TCP network, not all requests are responded to. It is possible that two or even multiple requests will result in a response. How can I use the read and write methods in the Channel obtained by channel_direct_tcpip to achieve this effect? Currently, I can only achieve "one request must have one response". I don't know how to do it.
I hope that the read and write methods of this Channel can handle their own things separately, just like the sender and receiver obtained by onshot::channel().
This is my current code. The problem with the code is that read_channel often times out.
pubfntest_ssh_tunnel_with_ssh2(){letmut session = Session::new().unwrap();let tcp = TcpStream::connect(SSH_ADDR).unwrap();
session.set_tcp_stream(tcp);
session.handshake().unwrap();
session.set_keepalive(false,5);let private_key = Path::new(SSH_KEY);
session.userauth_pubkey_file("tz",None, private_key,Some(SSH_KEY_PASSPHRASE)).unwrap();let session = Arc::new(session);let listener = net::TcpListener::bind("127.0.0.1:5000").unwrap();for stream in listener.incoming(){letmut stream = stream.unwrap();let ssh_session = Arc::clone(&session);
thread::spawn(move || {letmut channel = ssh_session.channel_direct_tcpip("127.0.0.1",2379,None).unwrap();loop{let(request, size) = read_stream(&mut stream);if size <= 0{break;}
channel.write_all(&request[..size]).unwrap();
channel.flush().unwrap();// This always times out when there is no response to this requestlet(response, size) = read_channel(&mut channel);if size <= 0{break}
stream.write_all(&response[..size]).unwrap();
stream.flush().unwrap();}
channel.close().unwrap();});}}
The text was updated successfully, but these errors were encountered:
Usually when proxying a TCP network, not all requests are responded to. It is possible that two or even multiple requests will result in a response. How can I use the read and write methods in the
Channel
obtained bychannel_direct_tcpip
to achieve this effect? Currently, I can only achieve "one request must have one response". I don't know how to do it.I hope that the read and write methods of this Channel can handle their own things separately, just like the sender and receiver obtained by
onshot::channel()
.This is my current code. The problem with the code is that read_channel often times out.
The text was updated successfully, but these errors were encountered: