示例#1
0
 /// <summary>
 /// Creates a new Telnet instance
 /// </summary>
 /// <param name="IPAddr">IP Address of the Device</param>
 /// <param name="port">Telnet port for the listening device</param>
 /// <returns> Bool value representing the success of connection</returns>
 public void Connect(IPAddress IPAddr, int port)
 {
     try
     {
         Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         socket.Connect(IPAddr, port);
         telnet  = new TelnetStream(new NetworkStream(socket));
         psychic = new Expector(telnet);
         psychic.ExpectTimeout = new TimeSpan(0, 0, 8); //5 sec timeout
         _status = "Online";
     }
     catch (SocketException)
     {
         _status = "Connection Error";
     }
     catch
     {
         _status = "Error";
     }
 }
示例#2
0
        /// <summary>
        /// Creates a new Telnet instance
        /// </summary>
        /// <param name="IPAddr">IP Address of the Device</param>
        /// <param name="port">Telnet port for the listening device</param>
        /// <returns> Bool value representing the success of connection</returns>
        public void Connect(IPAddress IPAddr, int port)
        {
            try
            {
                TcpClient tcl = new TcpClient(Dns.GetHostEntry(IPAddr).HostName, port);

                System.IO.Stream st = tcl.GetStream();
                telnet  = new TelnetStream(st);
                psychic = new Expector(telnet);
                psychic.ExpectTimeout = new TimeSpan(0, 0, 5); //5 sec timeout
                _status = "Online";
            }
            catch (SocketException)
            {
                _status = "Connection Error";
            }
            catch
            {
                _status = "Error";
            }
        }