Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implementing a TelnetApp. using Winsock control!

Application/Utility Simulation

Implementing a TelnetApp. using Winsock control!

by  kaleatul  Posted    (Edited  )
Implementing a TelnetApp. using Winsock control!
A Preview
[img http://www.geocities.com/kaleatul/telnet.jpg ]
Assumptions...
Code:
sckTelnet -> WinSock control
sckTelnet.Protocal = sckTCPProtocal

timerTel -> Timer Control with Interval 500
------------------------------------------------------

Option Explicit
Dim X As Integer
------------------------------------------------------
Private Sub cmdConnect_Click()
    If Trim(txtRHostName.Text) = "" Or Trim(txtPortNo.Text) = "" Then
        MsgBox "Invalid Entry..."
    Else
        sckTelnet.RemoteHost = txtRHostName.Text
        sckTelnet.RemotePort = Val(txtPortNo.Text)
        sckTelnet.Connect
        timerTel.Enabled = True
        Frame1.Enabled = False
    End If
End Sub
------------------------------------------------------
Private Sub cmdSend_Click()
    sckTelnet.SendData txtCommand.Text + vbNewLine
    txtCommand.Text = ""
End Sub
------------------------------------------------------
Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = 27 Then
        Unload Me
    End If
End Sub
------------------------------------------------------
Private Sub Form_Load()
    Frame2.Enabled = False
    timerTel.Enabled = False
End Sub
------------------------------------------------------
Private Sub sckTelnet_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String
    sckTelnet.GetData strData
    txtReply.Text = strData + vbNewLine
End Sub
------------------------------------------------------
Private Sub timerTel_Timer()
    X = X + 1
    If X > 20 Then
        MsgBox "Problem encountered connecting Host..."
        timerTel.Enabled = False
        Frame1.Enabled = True
        X = 0
        Label6.Caption = X
    End If
        
    If sckTelnet.State = 7 Then
        Frame2.Enabled = True
        Frame1.Enabled = False
        lblStatus.Caption = "Connected"
        timerTel.Enabled = False
        cmdSend.Default = True
    Else
        lblStatus.Caption = "State:" & sckTelnet.State
    End If

    Label6.Caption = X
End Sub
------------------------------------------------------

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top