home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / dos_win / winsock / packages / powertcp.exe / TELNETEX.FR_ / TELNETEX.bin (.txt)
Encoding:
Visual Basic Form  |  1995-02-16  |  12.9 KB  |  388 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Telnet Example"
  4.    ClientHeight    =   5820
  5.    ClientLeft      =   972
  6.    ClientTop       =   1428
  7.    ClientWidth     =   7368
  8.    Height          =   6192
  9.    Icon            =   TELNETEX.FRX:0000
  10.    Left            =   924
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5820
  13.    ScaleWidth      =   7368
  14.    Top             =   1104
  15.    Width           =   7464
  16.    Begin PowerTCP_TNT tntConnectFrom 
  17.       Flags           =   0
  18.       Left            =   6300
  19.       LocalDotAddr    =   ""
  20.       OemLicense      =   ""
  21.       RemoteHost      =   ""
  22.       RemotePort      =   23
  23.       Top             =   4500
  24.    End
  25.    Begin PowerTCP_TNT tntConnectTo 
  26.       Flags           =   0
  27.       Left            =   6300
  28.       LocalDotAddr    =   ""
  29.       OemLicense      =   ""
  30.       RemoteHost      =   ""
  31.       RemotePort      =   23
  32.       Top             =   2100
  33.    End
  34.    Begin PowerTCP_TNT tntListen 
  35.       Flags           =   0
  36.       Left            =   1980
  37.       LocalDotAddr    =   ""
  38.       OemLicense      =   ""
  39.       RemoteHost      =   ""
  40.       RemotePort      =   23
  41.       Top             =   300
  42.    End
  43.    Begin CommandButton cmdExit 
  44.       Caption         =   "E&xit"
  45.       Height          =   375
  46.       Left            =   6000
  47.       TabIndex        =   14
  48.       Top             =   120
  49.       Width           =   1215
  50.    End
  51.    Begin Frame Frame3 
  52.       Caption         =   "Connected &From"
  53.       Height          =   1935
  54.       Left            =   120
  55.       TabIndex        =   13
  56.       Top             =   3720
  57.       Width           =   7095
  58.       Begin CommandButton cmdConnectFromClose 
  59.          Caption         =   "Clo&se"
  60.          Enabled         =   0   'False
  61.          Height          =   375
  62.          Left            =   5760
  63.          TabIndex        =   16
  64.          Top             =   1440
  65.          Width           =   1215
  66.       End
  67.       Begin TextBox txtConnectFrom 
  68.          FontBold        =   0   'False
  69.          FontItalic      =   0   'False
  70.          FontName        =   "Fixedsys"
  71.          FontSize        =   10.8
  72.          FontStrikethru  =   0   'False
  73.          FontUnderline   =   0   'False
  74.          Height          =   1455
  75.          Left            =   120
  76.          MultiLine       =   -1  'True
  77.          ScrollBars      =   2  'Vertical
  78.          TabIndex        =   15
  79.          Top             =   360
  80.          Width           =   5175
  81.       End
  82.    End
  83.    Begin Frame Frame2 
  84.       Caption         =   "&Listen"
  85.       Height          =   855
  86.       Left            =   120
  87.       TabIndex        =   0
  88.       Top             =   120
  89.       Width           =   5175
  90.       Begin CommandButton cmdStop 
  91.          Caption         =   "&Stop"
  92.          Height          =   375
  93.          Left            =   3720
  94.          TabIndex        =   4
  95.          Top             =   360
  96.          Width           =   1215
  97.       End
  98.       Begin TextBox txtListenPort 
  99.          Height          =   375
  100.          Left            =   600
  101.          TabIndex        =   2
  102.          Text            =   "23"
  103.          Top             =   360
  104.          Width           =   1215
  105.       End
  106.       Begin CommandButton cmdListen 
  107.          Caption         =   "&Listen"
  108.          Height          =   375
  109.          Left            =   2280
  110.          TabIndex        =   3
  111.          Top             =   360
  112.          Width           =   1215
  113.       End
  114.       Begin Label Label3 
  115.          Caption         =   "&Port:"
  116.          Height          =   375
  117.          Left            =   120
  118.          TabIndex        =   1
  119.          Top             =   360
  120.          Width           =   1215
  121.       End
  122.    End
  123.    Begin Frame Frame1 
  124.       Caption         =   "Connect &To"
  125.       Height          =   2535
  126.       Left            =   120
  127.       TabIndex        =   5
  128.       Top             =   1080
  129.       Width           =   7095
  130.       Begin CommandButton cmdConnectToClose 
  131.          Caption         =   "C&lose"
  132.          Enabled         =   0   'False
  133.          Height          =   375
  134.          Left            =   5760
  135.          TabIndex        =   11
  136.          Top             =   2040
  137.          Width           =   1215
  138.       End
  139.       Begin TextBox txtConnectToPort 
  140.          Height          =   375
  141.          Left            =   5640
  142.          TabIndex        =   9
  143.          Text            =   "23"
  144.          Top             =   240
  145.          Width           =   1335
  146.       End
  147.       Begin TextBox txtConnectToAddress 
  148.          Height          =   375
  149.          Left            =   3240
  150.          TabIndex        =   7
  151.          Text            =   "x.x.x.x"
  152.          Top             =   240
  153.          Width           =   1335
  154.       End
  155.       Begin CommandButton cmdConnect 
  156.          Caption         =   "&Connect"
  157.          Height          =   375
  158.          Left            =   5760
  159.          TabIndex        =   10
  160.          Top             =   1560
  161.          Width           =   1215
  162.       End
  163.       Begin TextBox txtConnectTo 
  164.          FontBold        =   0   'False
  165.          FontItalic      =   0   'False
  166.          FontName        =   "Fixedsys"
  167.          FontSize        =   10.8
  168.          FontStrikethru  =   0   'False
  169.          FontUnderline   =   0   'False
  170.          Height          =   1455
  171.          Left            =   120
  172.          MultiLine       =   -1  'True
  173.          ScrollBars      =   2  'Vertical
  174.          TabIndex        =   12
  175.          Top             =   960
  176.          Width           =   5175
  177.       End
  178.       Begin Label Label2 
  179.          Caption         =   "&Port:"
  180.          Height          =   495
  181.          Left            =   5040
  182.          TabIndex        =   8
  183.          Top             =   240
  184.          Width           =   1215
  185.       End
  186.       Begin Label Label1 
  187.          Caption         =   "&Address:"
  188.          Height          =   495
  189.          Left            =   2280
  190.          TabIndex        =   6
  191.          Top             =   240
  192.          Width           =   1215
  193.       End
  194.    End
  195. ' IMPORTANT: We MUST use the API MessageBox function
  196. ' instead of the VB MsgBox function. See the PowerTCP
  197. ' README for more information.
  198. Declare Function MessageBox Lib "User" (ByVal hWnd As Integer, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Integer) As Integer
  199. Sub cmdConnect_Click ()
  200.     ' Set the properties of the remote computer
  201.     tntConnectTo.RemoteHost = txtConnectToAddress.Text
  202.     tntConnectTo.RemotePort = Val(txtConnectToPort.Text)
  203.     ' Make the connection
  204.     tntConnectTo.Action = CONNECT
  205. End Sub
  206. Sub cmdConnectFromClose_Click ()
  207.     tntConnectFrom.Action = CLOSECOMM
  208. End Sub
  209. Sub cmdConnectToClose_Click ()
  210.     tntConnectTo.Action = CLOSECOMM
  211. End Sub
  212. Sub cmdExit_Click ()
  213.     tntConnectTo.Action = ABORTCOMM
  214.     tntListen.Action = ABORTCOMM
  215.     tntConnectFrom.Action = ABORTCOMM
  216.     End
  217. End Sub
  218. Sub cmdListen_Click ()
  219.     ' Set the mode of tntListen to Listen
  220.     tntListen.LocalPort = Val(txtListenPort.Text)
  221.     tntListen.Action = LISTEN
  222.     ' Make the "Stop" button enabled
  223.     cmdStop.Enabled = True
  224. End Sub
  225. Sub cmdStop_Click ()
  226.     tntListen.Action = CLOSECOMM
  227. End Sub
  228. Sub Form_Unload (Cancel As Integer)
  229.     End
  230. End Sub
  231. Sub tntConnectFrom_Cmd (Cmd As Integer, TelnetOption As Integer, SubOption As String)
  232.     ' When we sent a suboption, it must be 6 bytes long
  233.     Dim MySubOption As String * 6
  234.     Select Case Cmd
  235.     Case DO_CMD
  236.         If TelnetOption = TERMINAL_TYPE Then
  237.             ' We will support this option
  238.             tntConnectFrom.WillOption = TERMINAL_TYPE
  239.         Else
  240.             ' We don't support any others
  241.             tntConnectFrom.WontOption = TelnetOption
  242.         End If
  243.     Case DONT_CMD
  244.         tntConnectFrom.WontOption = TelnetOption
  245.     Case SB_CMD
  246.         ' We support the TTY terminal type
  247.         If TelnetOption = TERMINAL_TYPE Then
  248.             MySubOption = Chr$(0) & "tty"
  249.             tntConnectFrom.SubOption = MySubOption
  250.             tntConnectFrom.DoSubOption = TERMINAL_TYPE
  251.         End If
  252.     Case WILL_CMD
  253.         If TelnetOption = SUPPRESS_GO_AHEAD Then
  254.             ' We will support this option
  255.             tntConnectFrom.DoOption = SUPPRESS_GO_AHEAD
  256.         Else
  257.             ' We don't support any others
  258.             tntConnectFrom.DontOption = TelnetOption
  259.         End If
  260.     Case WONT_CMD
  261.         ' tntConnectFrom.DontOption = TelnetOption
  262.     End Select
  263. End Sub
  264. Sub tntConnectFrom_Connect ()
  265.     cmdConnectFromClose.Enabled = True
  266. End Sub
  267. Sub tntConnectFrom_Exception (ErrorCode As Integer, ErrorDesc As String)
  268.     If ErrorCode = PT_CLOSED Or ErrorCode = PT_ABORTED Then
  269.         suc% = MessageBox(Me.hWnd, "The connection was closed.", App.Title, 0)
  270.         cmdConnectFromClose.Enabled = False
  271.     Else
  272.         ' An unexpected error occurred--
  273.         ' notify the user and close the connection
  274.         suc% = MessageBox(Me.hWnd, ErrorDesc, App.Title, 0)
  275.         tntConnectTo.Action = CLOSECOMM
  276.     End If
  277. End Sub
  278. Sub tntConnectFrom_Recv (RecvData As String)
  279.     If RecvData = "" Then
  280.         ' The connection was closed
  281.         cmdConnect.Enabled = True
  282.         cmdConnectFromClose.Enabled = False
  283.         suc% = MessageBox(Me.hWnd, "The connection was closed.", App.Title, 0)
  284.     Else
  285.         txtConnectFrom.Text = txtConnectFrom.Text + RecvData
  286.         txtConnectFrom.SelStart = Len(txtConnectFrom.Text)
  287.     End If
  288. End Sub
  289. Sub tntConnectTo_Cmd (Cmd As Integer, TelnetOption As Integer, SubOption As String)
  290.     ' Which command is it?
  291.     Select Case Cmd
  292.     Case DO_CMD
  293.         If TelnetOption = TERMINAL_TYPE Then
  294.             ' We will support this option
  295.             tntConnectTo.WillOption = TERMINAL_TYPE
  296.         Else
  297.             ' We don't support any others
  298.             tntConnectTo.WontOption = TelnetOption
  299.         End If
  300.     Case DONT_CMD
  301.         ' We must agree for a DON'T
  302.         tntConnectTo.WontOption = TelnetOption
  303.     Case SB_CMD
  304.         ' We support the TTY terminal type
  305.         If TelnetOption = TERMINAL_TYPE Then
  306.             tntConnectTo.SubOption = Chr$(0) & "tty"
  307.             tntConnectTo.DoSubOption = TERMINAL_TYPE
  308.         End If
  309.     Case WILL_CMD
  310.         If TelnetOption = SUPPRESS_GO_AHEAD Then
  311.             ' We will support this option
  312.             tntConnectTo.DoOption = SUPPRESS_GO_AHEAD
  313.         Else
  314.             ' We don't support any others
  315.             tntConnectTo.DontOption = TelnetOption
  316.         End If
  317.     Case WONT_CMD
  318.         ' We must agree for a WON'T
  319.         ' tntConnectTo.DontOption = TelnetOption
  320.     End Select
  321. End Sub
  322. Sub tntConnectTo_Connect ()
  323.     ' Make the Connect button disabled,
  324.     ' and the Close button enabled.
  325.     cmdConnect.Enabled = False
  326.     cmdConnectToClose.Enabled = True
  327.     ' We do not want to support echoing
  328.     tntConnectTo.DontOption = ECHO
  329. End Sub
  330. Sub tntConnectTo_Exception (ErrorCode As Integer, ErrorDesc As String)
  331.     ' An unexpected error occurred--
  332.     ' notify the user and close the connection
  333.     suc% = MessageBox(Me.hWnd, ErrorDesc, App.Title, 0)
  334. End Sub
  335. Sub tntConnectTo_Recv (RecvData As String)
  336.     If RecvData = "" Then
  337.         ' The connection was closed
  338.         cmdConnect.Enabled = True
  339.         cmdConnectToClose.Enabled = False
  340.         
  341.         suc% = MessageBox(Me.hWnd, "The connection was closed.", App.Title, 0)
  342.     Else
  343.         txtConnectTo.Text = txtConnectTo.Text + RecvData
  344.         txtConnectTo.SelStart = Len(txtConnectTo.Text)
  345.     End If
  346. End Sub
  347. Sub tntListen_Accept (NewSession As Long)
  348.     ' We must pass the connection on to tntConnectFrom
  349.     tntConnectFrom.Session = NewSession
  350. End Sub
  351. Sub tntListen_Exception (ErrorCode As Integer, ErrorDesc As String)
  352.     ' An unexpected error occurred--
  353.     ' notify the user and close the connection
  354.     suc% = MessageBox(Me.hWnd, ErrorDesc, App.Title, 0)
  355. End Sub
  356. Sub tntListen_Listen ()
  357.     ' Make the Listen button disabled,
  358.     ' and the Stop button enabled.
  359.     cmdListen.Enabled = False
  360.     cmdStop.Enabled = True
  361. End Sub
  362. Sub tntListen_Recv (RecvData As String)
  363.     ' The connection was closed
  364.     cmdListen.Enabled = True
  365.     cmdStop.Enabled = False
  366.     suc% = MessageBox(Me.hWnd, "Listening was stopped.", App.Title, 0)
  367. End Sub
  368. Sub txtConnectFrom_KeyPress (KeyAscii As Integer)
  369.     ' Send the character to the other end
  370.     ' of the connection.
  371.     tntConnectFrom.Send = Chr(KeyAscii)
  372.     ' Make sure the character appears at
  373.     ' the end of the text box
  374.     txtConnectFrom.SelStart = Len(txtConnectFrom.Text)
  375. End Sub
  376. Sub txtConnectTo_KeyPress (KeyAscii As Integer)
  377.     ' Send the character to the other end
  378.     ' of the connection.
  379.     tntConnectTo.Send = Chr(KeyAscii)
  380.     ' Note: carriage returns, went sent, should be followed
  381.     ' by the linefeed character, according to the TELNET
  382.     ' protocol
  383.     If KeyAscii = 13 Then tntConnectTo.Send = Chr$(10)
  384.     ' Make sure the character appears at
  385.     ' the end of the text box
  386.     txtConnectTo.SelStart = Len(txtConnectTo.Text)
  387. End Sub
  388.