home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Form1
- Caption = "Telnet Example"
- ClientHeight = 5820
- ClientLeft = 972
- ClientTop = 1428
- ClientWidth = 7368
- Height = 6192
- Icon = TELNETEX.FRX:0000
- Left = 924
- LinkTopic = "Form1"
- ScaleHeight = 5820
- ScaleWidth = 7368
- Top = 1104
- Width = 7464
- Begin PowerTCP_TNT tntConnectFrom
- Flags = 0
- Left = 6300
- LocalDotAddr = ""
- OemLicense = ""
- RemoteHost = ""
- RemotePort = 23
- Top = 4500
- End
- Begin PowerTCP_TNT tntConnectTo
- Flags = 0
- Left = 6300
- LocalDotAddr = ""
- OemLicense = ""
- RemoteHost = ""
- RemotePort = 23
- Top = 2100
- End
- Begin PowerTCP_TNT tntListen
- Flags = 0
- Left = 1980
- LocalDotAddr = ""
- OemLicense = ""
- RemoteHost = ""
- RemotePort = 23
- Top = 300
- End
- Begin CommandButton cmdExit
- Caption = "E&xit"
- Height = 375
- Left = 6000
- TabIndex = 14
- Top = 120
- Width = 1215
- End
- Begin Frame Frame3
- Caption = "Connected &From"
- Height = 1935
- Left = 120
- TabIndex = 13
- Top = 3720
- Width = 7095
- Begin CommandButton cmdConnectFromClose
- Caption = "Clo&se"
- Enabled = 0 'False
- Height = 375
- Left = 5760
- TabIndex = 16
- Top = 1440
- Width = 1215
- End
- Begin TextBox txtConnectFrom
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "Fixedsys"
- FontSize = 10.8
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 1455
- Left = 120
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 15
- Top = 360
- Width = 5175
- End
- End
- Begin Frame Frame2
- Caption = "&Listen"
- Height = 855
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 5175
- Begin CommandButton cmdStop
- Caption = "&Stop"
- Height = 375
- Left = 3720
- TabIndex = 4
- Top = 360
- Width = 1215
- End
- Begin TextBox txtListenPort
- Height = 375
- Left = 600
- TabIndex = 2
- Text = "23"
- Top = 360
- Width = 1215
- End
- Begin CommandButton cmdListen
- Caption = "&Listen"
- Height = 375
- Left = 2280
- TabIndex = 3
- Top = 360
- Width = 1215
- End
- Begin Label Label3
- Caption = "&Port:"
- Height = 375
- Left = 120
- TabIndex = 1
- Top = 360
- Width = 1215
- End
- End
- Begin Frame Frame1
- Caption = "Connect &To"
- Height = 2535
- Left = 120
- TabIndex = 5
- Top = 1080
- Width = 7095
- Begin CommandButton cmdConnectToClose
- Caption = "C&lose"
- Enabled = 0 'False
- Height = 375
- Left = 5760
- TabIndex = 11
- Top = 2040
- Width = 1215
- End
- Begin TextBox txtConnectToPort
- Height = 375
- Left = 5640
- TabIndex = 9
- Text = "23"
- Top = 240
- Width = 1335
- End
- Begin TextBox txtConnectToAddress
- Height = 375
- Left = 3240
- TabIndex = 7
- Text = "x.x.x.x"
- Top = 240
- Width = 1335
- End
- Begin CommandButton cmdConnect
- Caption = "&Connect"
- Height = 375
- Left = 5760
- TabIndex = 10
- Top = 1560
- Width = 1215
- End
- Begin TextBox txtConnectTo
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "Fixedsys"
- FontSize = 10.8
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 1455
- Left = 120
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 12
- Top = 960
- Width = 5175
- End
- Begin Label Label2
- Caption = "&Port:"
- Height = 495
- Left = 5040
- TabIndex = 8
- Top = 240
- Width = 1215
- End
- Begin Label Label1
- Caption = "&Address:"
- Height = 495
- Left = 2280
- TabIndex = 6
- Top = 240
- Width = 1215
- End
- End
- ' IMPORTANT: We MUST use the API MessageBox function
- ' instead of the VB MsgBox function. See the PowerTCP
- ' README for more information.
- Declare Function MessageBox Lib "User" (ByVal hWnd As Integer, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Integer) As Integer
- Sub cmdConnect_Click ()
- ' Set the properties of the remote computer
- tntConnectTo.RemoteHost = txtConnectToAddress.Text
- tntConnectTo.RemotePort = Val(txtConnectToPort.Text)
- ' Make the connection
- tntConnectTo.Action = CONNECT
- End Sub
- Sub cmdConnectFromClose_Click ()
- tntConnectFrom.Action = CLOSECOMM
- End Sub
- Sub cmdConnectToClose_Click ()
- tntConnectTo.Action = CLOSECOMM
- End Sub
- Sub cmdExit_Click ()
- tntConnectTo.Action = ABORTCOMM
- tntListen.Action = ABORTCOMM
- tntConnectFrom.Action = ABORTCOMM
- End
- End Sub
- Sub cmdListen_Click ()
- ' Set the mode of tntListen to Listen
- tntListen.LocalPort = Val(txtListenPort.Text)
- tntListen.Action = LISTEN
- ' Make the "Stop" button enabled
- cmdStop.Enabled = True
- End Sub
- Sub cmdStop_Click ()
- tntListen.Action = CLOSECOMM
- End Sub
- Sub Form_Unload (Cancel As Integer)
- End
- End Sub
- Sub tntConnectFrom_Cmd (Cmd As Integer, TelnetOption As Integer, SubOption As String)
- ' When we sent a suboption, it must be 6 bytes long
- Dim MySubOption As String * 6
- Select Case Cmd
- Case DO_CMD
- If TelnetOption = TERMINAL_TYPE Then
- ' We will support this option
- tntConnectFrom.WillOption = TERMINAL_TYPE
- Else
- ' We don't support any others
- tntConnectFrom.WontOption = TelnetOption
- End If
- Case DONT_CMD
- tntConnectFrom.WontOption = TelnetOption
- Case SB_CMD
- ' We support the TTY terminal type
- If TelnetOption = TERMINAL_TYPE Then
- MySubOption = Chr$(0) & "tty"
- tntConnectFrom.SubOption = MySubOption
- tntConnectFrom.DoSubOption = TERMINAL_TYPE
- End If
- Case WILL_CMD
- If TelnetOption = SUPPRESS_GO_AHEAD Then
- ' We will support this option
- tntConnectFrom.DoOption = SUPPRESS_GO_AHEAD
- Else
- ' We don't support any others
- tntConnectFrom.DontOption = TelnetOption
- End If
- Case WONT_CMD
- ' tntConnectFrom.DontOption = TelnetOption
- End Select
- End Sub
- Sub tntConnectFrom_Connect ()
- cmdConnectFromClose.Enabled = True
- End Sub
- Sub tntConnectFrom_Exception (ErrorCode As Integer, ErrorDesc As String)
- If ErrorCode = PT_CLOSED Or ErrorCode = PT_ABORTED Then
- suc% = MessageBox(Me.hWnd, "The connection was closed.", App.Title, 0)
- cmdConnectFromClose.Enabled = False
- Else
- ' An unexpected error occurred--
- ' notify the user and close the connection
- suc% = MessageBox(Me.hWnd, ErrorDesc, App.Title, 0)
- tntConnectTo.Action = CLOSECOMM
- End If
- End Sub
- Sub tntConnectFrom_Recv (RecvData As String)
- If RecvData = "" Then
- ' The connection was closed
- cmdConnect.Enabled = True
- cmdConnectFromClose.Enabled = False
- suc% = MessageBox(Me.hWnd, "The connection was closed.", App.Title, 0)
- Else
- txtConnectFrom.Text = txtConnectFrom.Text + RecvData
- txtConnectFrom.SelStart = Len(txtConnectFrom.Text)
- End If
- End Sub
- Sub tntConnectTo_Cmd (Cmd As Integer, TelnetOption As Integer, SubOption As String)
- ' Which command is it?
- Select Case Cmd
- Case DO_CMD
- If TelnetOption = TERMINAL_TYPE Then
- ' We will support this option
- tntConnectTo.WillOption = TERMINAL_TYPE
- Else
- ' We don't support any others
- tntConnectTo.WontOption = TelnetOption
- End If
- Case DONT_CMD
- ' We must agree for a DON'T
- tntConnectTo.WontOption = TelnetOption
- Case SB_CMD
- ' We support the TTY terminal type
- If TelnetOption = TERMINAL_TYPE Then
- tntConnectTo.SubOption = Chr$(0) & "tty"
- tntConnectTo.DoSubOption = TERMINAL_TYPE
- End If
- Case WILL_CMD
- If TelnetOption = SUPPRESS_GO_AHEAD Then
- ' We will support this option
- tntConnectTo.DoOption = SUPPRESS_GO_AHEAD
- Else
- ' We don't support any others
- tntConnectTo.DontOption = TelnetOption
- End If
- Case WONT_CMD
- ' We must agree for a WON'T
- ' tntConnectTo.DontOption = TelnetOption
- End Select
- End Sub
- Sub tntConnectTo_Connect ()
- ' Make the Connect button disabled,
- ' and the Close button enabled.
- cmdConnect.Enabled = False
- cmdConnectToClose.Enabled = True
- ' We do not want to support echoing
- tntConnectTo.DontOption = ECHO
- End Sub
- Sub tntConnectTo_Exception (ErrorCode As Integer, ErrorDesc As String)
- ' An unexpected error occurred--
- ' notify the user and close the connection
- suc% = MessageBox(Me.hWnd, ErrorDesc, App.Title, 0)
- End Sub
- Sub tntConnectTo_Recv (RecvData As String)
- If RecvData = "" Then
- ' The connection was closed
- cmdConnect.Enabled = True
- cmdConnectToClose.Enabled = False
-
- suc% = MessageBox(Me.hWnd, "The connection was closed.", App.Title, 0)
- Else
- txtConnectTo.Text = txtConnectTo.Text + RecvData
- txtConnectTo.SelStart = Len(txtConnectTo.Text)
- End If
- End Sub
- Sub tntListen_Accept (NewSession As Long)
- ' We must pass the connection on to tntConnectFrom
- tntConnectFrom.Session = NewSession
- End Sub
- Sub tntListen_Exception (ErrorCode As Integer, ErrorDesc As String)
- ' An unexpected error occurred--
- ' notify the user and close the connection
- suc% = MessageBox(Me.hWnd, ErrorDesc, App.Title, 0)
- End Sub
- Sub tntListen_Listen ()
- ' Make the Listen button disabled,
- ' and the Stop button enabled.
- cmdListen.Enabled = False
- cmdStop.Enabled = True
- End Sub
- Sub tntListen_Recv (RecvData As String)
- ' The connection was closed
- cmdListen.Enabled = True
- cmdStop.Enabled = False
- suc% = MessageBox(Me.hWnd, "Listening was stopped.", App.Title, 0)
- End Sub
- Sub txtConnectFrom_KeyPress (KeyAscii As Integer)
- ' Send the character to the other end
- ' of the connection.
- tntConnectFrom.Send = Chr(KeyAscii)
- ' Make sure the character appears at
- ' the end of the text box
- txtConnectFrom.SelStart = Len(txtConnectFrom.Text)
- End Sub
- Sub txtConnectTo_KeyPress (KeyAscii As Integer)
- ' Send the character to the other end
- ' of the connection.
- tntConnectTo.Send = Chr(KeyAscii)
- ' Note: carriage returns, went sent, should be followed
- ' by the linefeed character, according to the TELNET
- ' protocol
- If KeyAscii = 13 Then tntConnectTo.Send = Chr$(10)
- ' Make sure the character appears at
- ' the end of the text box
- txtConnectTo.SelStart = Len(txtConnectTo.Text)
- End Sub
-