【发布时间】:2012-01-28 15:02:15
【问题描述】:
我有一个大问题,但可能对我来说只是大问题:)。 “终端。绑定(客户端);”如果 IP 错误,此行会导致我的程序挂起。我想在 5 秒后停止这个程序,因为如果 10 秒后 IP 错误,所有程序都会挂起.. :(
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rebex.TerminalEmulation;
using Rebex.Security;
using Rebex.Net;
namespace Routers_info_v._1
{
class Program
{
static void Main(string[] args)
{
Telnet client = new Telnet("192.168.1.1");
VirtualTerminal terminal = new VirtualTerminal(80, 25);
terminal.Bind(client);
terminal.SendToServer("pass\r");
terminal.SendToServer("sys ver\r");
TerminalState state;
do
{
state = terminal.Process(2000);
} while (state == TerminalState.DataReceived);
terminal.Save("terminal.txt", TerminalCaptureFormat.Text, TerminalCaptureOptions.DoNotHideCursor);
terminal.Unbind();
terminal.Dispose();
}
}
}
【问题讨论】:
-
你会想把它扔到一个线程中并在一段时间后终止线程。
-
你等了 30 秒吗?我认为这是建立连接的一般超时时间。换句话说,您的代码可能会阻止尝试连接到错误的 IP。我认为它最终应该返回并可能导致异常。只是猜测。