【发布时间】:2015-09-15 07:31:45
【问题描述】:
我正在尝试制作一个 SSH 隧道应用程序。我成功地打开了一个带有动态端口的隧道,它一直工作到浏览器建立第一个连接为止。加载一个页面后,隧道不再工作,我无法打开下一页,直到我重新启动隧道。有时会有例外
“对象引用未设置为对象的实例。” Renci.SshNet.dll 中的“System.NullReferenceException”。
我的代码如下:
SshClient client;
ForwardedPortDynamic port;
public void Start(string server, string user, string password, int serverport=22)
{
client = new SshClient(server, user, password);
client.KeepAliveInterval = new TimeSpan(0, 0, 5);
client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 20);
client.Connect();
if (client.IsConnected)
{
try
{
port = new ForwardedPortDynamic("127.0.0.1", 1080);
client.AddForwardedPort(port);
port.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
public void Stop()
{
port.Stop();
port.Dispose();
client.Disconnect();
client.Dispose();
}
它有什么问题?你能帮我让我的应用程序工作吗?非常感谢!
【问题讨论】:
-
错误发生在哪一行?
-
我建议您调试您的应用程序。设置断点,然后检查出错的地方。
-
如果异常发生在第三方库内部,并且如果 OP 没有更改库代码,则可能不是重复的。
-
当我尝试在页面停止加载时重新加载页面后,有时会在第三方库中发生异常。我想这是异常的原因,但我无法理解库和我的代码有什么问题。
标签: c# ssh proxy ssh-tunnel ssh.net