I am building an application, SWSH, which is a ssh client.
I am having trouble using the CreateShellStream()
function.
My code:
using (var ssh = new SshClient(ccinfo))
{
var keepgoing = true;
ssh.Connect();
string terminalName = "xterm-256color";
uint columns = 80;
uint rows = 160;
uint width = 80;
uint height = 160;
// arbitrarily chosen
int bufferSize = 500;
IDictionary<Renci.SshNet.Common.TerminalModes, uint> terminalModeValues = null;
var actual = ssh.CreateShellStream(terminalName, columns, rows, width, height, bufferSize, terminalModeValues);
//Read Thread
new System.Threading.Thread(() =>
{
while (actual.CanRead)
{
try
{
Console.WriteLine(actual.ReadLine());
}
catch (Exception)
{
keepgoing = false;
return;
}
}
keepgoing = false;
}).Start();
//Write Thread
new System.Threading.Thread(() =>
{
while (actual.CanWrite)
{
try
{
actual.WriteLine("");
actual.WriteLine(Console.ReadLine());
}
catch (Exception)
{
keepgoing = false;
return;
}
}
keepgoing = false;
}).Start();
}
I can render the output correctly but problem is in how it behaves.
Problem #1:
root:~/ # Cant write here
Problem #2: Double commands.
What am I doing wrong?
GitHub link: https://github.com/muhammadmuzzammil1998/SWSH/blob/43c17e95e684e6a3bced67bc7db04e6697972394/SWSH/Program.cs#L286
来源:https://stackoverflow.com/questions/48041574/ssh-net-createshellstream