Imports System.Threading Imports System Imports Jscape.Telnet Public Class TelnetExample Public WithEvents myTelnet As Telnet Private connect As Boolean = False Public Sub New(ByVal hostname As String) ' Instantiate Telnet myTelnet = New Telnet(hostname) ' Connect to telnet server myTelnet.Connect() ' Begin reading and writing data to telnet server Dim output As TelnetOutputStream = myTelnet.GetOutputStream() Dim input As String = "" Do input = Console.ReadLine() If (input <> "exit") Then output.PrintLn(input) Else Me.Connected = False End If Loop While Me.Connected = True ' Disconnect from telnet server myTelnet.Disconnect() End Sub Property Connected() As Boolean Get Return connect End Get Set(ByVal Value As Boolean) connect = Value End Set End Property Public Shared Sub Main() Dim hostname As String Dim example As TelnetExample Console.Write("Telnet server: ") hostname = Console.ReadLine() If (hostname <> "") Then example = New TelnetExample(hostname) End If End Sub Public Sub OnConnected(ByVal sender As Object, ByVal e As TelnetConnectedEventArgs) Handles myTelnet.ConnectedEvent Me.Connected = True Console.WriteLine("Connected to {0}:{1}", e.Host, e.Port) End Sub Private Sub OnDisconnected(ByVal sender As Object, ByVal e As TelnetDisconnectedEventArgs) Handles myTelnet.DisconnectedEvent Me.Connected = False Console.WriteLine("Disconnected.") End Sub Private Sub OnDoOption(ByVal sender As Object, ByVal e As TelnetDoOptionEventArgs) Handles myTelnet.DoOptionEvent myTelnet.SendWontOption(e.Option) End Sub Private Sub OnDontOption(ByVal sender As Object, ByVal e As TelnetDontOptionEventArgs) Handles myTelnet.DontOptionEvent myTelnet.SendDontOption(e.Option) End Sub Private Sub OnWillOption(ByVal sender As Object, ByVal e As TelnetWillOptionEventArgs) Handles myTelnet.WillOptionEvent myTelnet.SendDontOption(e.Option) End Sub Private Sub OnWontOption(ByVal sender As Object, ByVal e As TelnetWontOptionEventArgs) Handles myTelnet.WontOptionEvent myTelnet.SendWontOption(e.Option) End Sub Private Sub OnDataReceived(ByVal sender As Object, ByVal e As TelnetDataReceivedEventArgs) Handles myTelnet.DataReceivedEvent Console.Write(myTelnet.Encoding.GetString(e.Data)) End Sub End Class