SSH.NET CreateShellStream()

百般思念 提交于 2020-02-21 07:01:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!