home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / swrench / tcpecho.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-25  |  14.0 KB  |  472 lines

  1. VERSION 2.00
  2. Begin Form MainForm 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Echo"
  6.    ClientHeight    =   4050
  7.    ClientLeft      =   1905
  8.    ClientTop       =   1950
  9.    ClientWidth     =   7095
  10.    FontBold        =   0   'False
  11.    FontItalic      =   0   'False
  12.    FontName        =   "MS Sans Serif"
  13.    FontSize        =   8.25
  14.    FontStrikethru  =   0   'False
  15.    FontUnderline   =   0   'False
  16.    Height          =   4740
  17.    Left            =   1845
  18.    LinkTopic       =   "Form1"
  19.    ScaleHeight     =   4050
  20.    ScaleWidth      =   7095
  21.    Top             =   1320
  22.    Width           =   7215
  23.    Begin Socket Socket2 
  24.       Backlog         =   1
  25.       Binary          =   -1  'True
  26.       Blocking        =   -1  'True
  27.       Broadcast       =   0   'False
  28.       BufferSize      =   0
  29.       HostAddress     =   ""
  30.       HostFile        =   ""
  31.       HostName        =   ""
  32.       InLine          =   0   'False
  33.       Interval        =   0
  34.       KeepAlive       =   0   'False
  35.       Left            =   600
  36.       Linger          =   0
  37.       LocalPort       =   0
  38.       LocalService    =   ""
  39.       Peek            =   0   'False
  40.       Protocol        =   0
  41.       RecvLen         =   0
  42.       RemotePort      =   0
  43.       RemoteService   =   ""
  44.       ReuseAddress    =   0   'False
  45.       Route           =   -1  'True
  46.       SendLen         =   0
  47.       TabIndex        =   15
  48.       Timeout         =   0
  49.       Top             =   3480
  50.       Type            =   1
  51.       Urgent          =   0   'False
  52.    End
  53.    Begin Socket Socket1 
  54.       Backlog         =   1
  55.       Binary          =   -1  'True
  56.       Blocking        =   -1  'True
  57.       Broadcast       =   0   'False
  58.       BufferSize      =   0
  59.       HostAddress     =   ""
  60.       HostFile        =   ""
  61.       HostName        =   ""
  62.       InLine          =   0   'False
  63.       Interval        =   0
  64.       KeepAlive       =   0   'False
  65.       Left            =   120
  66.       Linger          =   0
  67.       LocalPort       =   0
  68.       LocalService    =   ""
  69.       Peek            =   0   'False
  70.       Protocol        =   0
  71.       RecvLen         =   0
  72.       RemotePort      =   0
  73.       RemoteService   =   ""
  74.       ReuseAddress    =   0   'False
  75.       Route           =   -1  'True
  76.       SendLen         =   0
  77.       TabIndex        =   14
  78.       Timeout         =   0
  79.       Top             =   3480
  80.       Type            =   1
  81.       Urgent          =   0   'False
  82.    End
  83.    Begin CommandButton CancelButton 
  84.       Caption         =   "Cancel"
  85.       Height          =   375
  86.       Left            =   4080
  87.       TabIndex        =   11
  88.       Top             =   3480
  89.       Width           =   1215
  90.    End
  91.    Begin CommandButton ActionButton 
  92.       Caption         =   "Connect"
  93.       Height          =   375
  94.       Left            =   1800
  95.       TabIndex        =   10
  96.       Top             =   3480
  97.       Width           =   1215
  98.    End
  99.    Begin TextBox SocketInput 
  100.       BackColor       =   &H00C0C0C0&
  101.       Height          =   285
  102.       Left            =   120
  103.       TabIndex        =   9
  104.       Top             =   3000
  105.       Width           =   6855
  106.    End
  107.    Begin ListBox SocketOutput 
  108.       BackColor       =   &H00C0C0C0&
  109.       FontBold        =   0   'False
  110.       FontItalic      =   0   'False
  111.       FontName        =   "Courier New"
  112.       FontSize        =   9.75
  113.       FontStrikethru  =   0   'False
  114.       FontUnderline   =   0   'False
  115.       Height          =   1230
  116.       Left            =   120
  117.       TabIndex        =   8
  118.       Top             =   1680
  119.       Width           =   6855
  120.    End
  121.    Begin Frame ServiceFrame 
  122.       BackColor       =   &H00C0C0C0&
  123.       Caption         =   "Service"
  124.       Height          =   1455
  125.       Left            =   3600
  126.       TabIndex        =   13
  127.       Top             =   120
  128.       Width           =   3375
  129.       Begin SpinButton Spin1 
  130.          Delay           =   150
  131.          Height          =   285
  132.          Left            =   1560
  133.          Top             =   840
  134.          Width           =   255
  135.       End
  136.       Begin TextBox ServicePort 
  137.          BackColor       =   &H00C0C0C0&
  138.          Height          =   285
  139.          Left            =   840
  140.          TabIndex        =   7
  141.          Top             =   840
  142.          Width           =   735
  143.       End
  144.       Begin TextBox ServiceName 
  145.          BackColor       =   &H00C0C0C0&
  146.          Height          =   285
  147.          Left            =   840
  148.          TabIndex        =   5
  149.          Top             =   480
  150.          Width           =   2175
  151.       End
  152.       Begin Label Label4 
  153.          BackStyle       =   0  'Transparent
  154.          Caption         =   "&Port:"
  155.          Height          =   255
  156.          Left            =   120
  157.          TabIndex        =   6
  158.          Top             =   840
  159.          Width           =   495
  160.       End
  161.       Begin Label Label3 
  162.          BackStyle       =   0  'Transparent
  163.          Caption         =   "&Name:"
  164.          Height          =   255
  165.          Left            =   120
  166.          TabIndex        =   4
  167.          Top             =   480
  168.          Width           =   615
  169.       End
  170.    End
  171.    Begin Frame RemoteFrame 
  172.       BackColor       =   &H00C0C0C0&
  173.       Caption         =   "System"
  174.       Height          =   1455
  175.       Left            =   120
  176.       TabIndex        =   12
  177.       Top             =   120
  178.       Width           =   3375
  179.       Begin ComboBox Hostname 
  180.          BackColor       =   &H00C0C0C0&
  181.          Height          =   300
  182.          Left            =   1200
  183.          Sorted          =   -1  'True
  184.          TabIndex        =   1
  185.          Top             =   480
  186.          Width           =   1935
  187.       End
  188.       Begin TextBox IPAddress 
  189.          BackColor       =   &H00C0C0C0&
  190.          Height          =   285
  191.          Left            =   1200
  192.          TabIndex        =   3
  193.          Top             =   840
  194.          Width           =   1575
  195.       End
  196.       Begin Label Label2 
  197.          BackStyle       =   0  'Transparent
  198.          Caption         =   "IP &Address:"
  199.          Height          =   255
  200.          Left            =   120
  201.          TabIndex        =   2
  202.          Top             =   840
  203.          Width           =   1095
  204.       End
  205.       Begin Label Label1 
  206.          BackStyle       =   0  'Transparent
  207.          Caption         =   "&Hostname:"
  208.          Height          =   255
  209.          Left            =   120
  210.          TabIndex        =   0
  211.          Top             =   480
  212.          Width           =   975
  213.       End
  214.    End
  215.    Begin Menu FileMenu 
  216.       Caption         =   "&File"
  217.       Begin Menu ExitApp 
  218.          Caption         =   "E&xit"
  219.       End
  220.    End
  221.    Begin Menu OptionsMenu 
  222.       Caption         =   "&Options"
  223.       Begin Menu ServerOption 
  224.          Caption         =   "Echo Server"
  225.       End
  226.    End
  227. Sub ActionButton_Click ()
  228.     If Not Socket1.Connected Then
  229.         On Error Resume Next
  230.         HostName.Text = Trim$(HostName.Text)
  231.         If Len(HostName.Text) > 0 Then
  232.             Socket1.HostName = HostName.Text
  233.             IPAddress.Text = Socket1.HostAddress
  234.         Else
  235.             Socket1.HostAddress = Trim$(IPAddress.Text)
  236.             HostName.Text = Socket1.HostName
  237.         End If
  238.         ServiceName.Text = Trim$(ServiceName.Text)
  239.         If Len(ServiceName.Text) > 0 Then
  240.             Socket1.RemoteService = ServiceName.Text
  241.             ServicePort.Text = Trim$(Str$(Socket1.RemotePort))
  242.         Else
  243.             Socket1.RemotePort = Val(Trim$(ServicePort.Text))
  244.             ServiceName.Text = Socket1.RemoteService
  245.         End If
  246.         Socket1.Action = SOCKET_CONNECT
  247.         If Err <> 0 Then Exit Sub
  248.         ActionButton.Enabled = False
  249.         ActionButton.Default = False
  250.     Else
  251.         Socket1.Action = SOCKET_CLOSE
  252.         ActionButton.Caption = "Connect"
  253.         ActionButton.Default = True
  254.         HostName.SetFocus
  255.     End If
  256.     Exit Sub
  257. End Sub
  258. Sub CancelButton_Click ()
  259.     Unload MainForm
  260. End Sub
  261. Sub ExitApp_Click ()
  262.     Unload MainForm
  263. End Sub
  264. Sub Form_Load ()
  265.     '
  266.     ' Initialize the socket control
  267.     '
  268.     Socket1.AddressFamily = AF_INET
  269.     Socket1.Binary = False
  270.     Socket1.Blocking = False
  271.     Socket1.BufferSize = 1024
  272.     Socket1.Protocol = IPPROTO_IP
  273.     Socket1.Type = SOCK_STREAM
  274.     Socket1.RemoteService = "echo"
  275.     Socket2.AddressFamily = AF_INET
  276.     Socket2.Binary = True
  277.     Socket2.Blocking = False
  278.     Socket2.HostAddress = INADDR_ANY
  279.     Socket2.Protocol = IPPROTO_IP
  280.     Socket2.Type = SOCK_STREAM
  281.     Socket2.LocalService = "echo"
  282.     '
  283.     ' Initialize hostname combo box
  284.     '
  285.     On Error Resume Next
  286.     Socket1.HostFile = "HOSTS"
  287.     If Err = 0 Then
  288.         Host$ = Socket1.GetFirstHost
  289.         While Host$ <> ""
  290.             HostName.AddItem Host$
  291.             Host$ = Socket1.GetNextHost
  292.         Wend
  293.     End If
  294.     Socket1.HostFile = ""
  295.     '
  296.     ' Initialize the other controls
  297.     '
  298.     ActionButton.Caption = "Connect"
  299.     ActionButton.Default = True
  300.     ActionButton.Enabled = False
  301.     ServiceName.Text = Socket1.RemoteService
  302.     ServicePort.Text = Trim$(Str$(Socket1.RemotePort))
  303. End Sub
  304. Sub Form_Unload (Cancel As Integer)
  305.     If Socket1.Connected Then Socket1.Action = SOCKET_CLOSE
  306.     If Socket2.Listening Or Socket2.Connected Then Socket2.Action = SOCKET_CLOSE
  307.     End
  308. End Sub
  309. Sub Hostname_Change ()
  310.     If Len(HostName.Text) > 0 Or Len(IPAddress.Text) > 0 Then
  311.         ActionButton.Enabled = True
  312.     Else
  313.         ActionButton.Enabled = False
  314.     End If
  315. End Sub
  316. Sub Hostname_Click ()
  317.     On Error Resume Next
  318.     Socket1.HostName = Trim(HostName.Text)
  319.     IPAddress.Text = Socket1.HostAddress
  320.     If Err = WSANO_DATA Then IPAddress.Text = ""
  321.     Exit Sub
  322. End Sub
  323. Sub Hostname_GotFocus ()
  324.     HostName.SelStart = 0
  325.     HostName.SelLength = Len(HostName.Text)
  326. End Sub
  327. Sub Hostname_LostFocus ()
  328.     Hostname_Click
  329. End Sub
  330. Sub IPAddress_Change ()
  331.     If Len(HostName.Text) > 0 Or Len(IPAddress.Text) > 0 Then
  332.         ActionButton.Enabled = True
  333.     Else
  334.         ActionButton.Enabled = False
  335.     End If
  336. End Sub
  337. Sub IPAddress_GotFocus ()
  338.     IPAddress.SelStart = 0
  339.     IPAddress.SelLength = Len(IPAddress.Text)
  340. End Sub
  341. Sub IPAddress_LostFocus ()
  342.     On Error Resume Next
  343.     Socket1.HostAddress = Trim(IPAddress.Text)
  344.     HostName.Text = Socket1.HostName
  345.     If Err = WSANO_DATA Then
  346.         MsgBox "That IP address is invalid"
  347.         Socket1.HostAddress = ""
  348.     End If
  349.     Exit Sub
  350. End Sub
  351. Sub ServerOption_Click ()
  352.     If Not Socket2.Connected Then
  353.         ServerOption.Checked = Not ServerOption.Checked
  354.         If ServerOption.Checked Then
  355.             Socket2.Action = SOCKET_LISTEN
  356.         Else
  357.             Socket2.Action = SOCKET_CLOSE
  358.         End If
  359.     End If
  360. End Sub
  361. Sub ServiceName_GotFocus ()
  362.     ServiceName.SelStart = 0
  363.     ServiceName.SelLength = Len(ServiceName.Text)
  364. End Sub
  365. Sub ServiceName_LostFocus ()
  366.     On Error GoTo BadName
  367.     Socket1.RemoteService = Trim(ServiceName.Text)
  368.     ServicePort.Text = Socket1.RemotePort
  369.     Exit Sub
  370. BadName:
  371.     ServicePort.Text = ""
  372.     ServiceName.SetFocus
  373.     Exit Sub
  374. End Sub
  375. Sub ServicePort_GotFocus ()
  376.     ServicePort.SelStart = 0
  377.     ServicePort.SelLength = Len(ServicePort.Text)
  378. End Sub
  379. Sub ServicePort_KeyPress (KeyAscii As Integer)
  380.     If KeyAscii > Asc("9") Then
  381.         KeyAscii = 0
  382.         Beep
  383.     ElseIf KeyAscii >= Asc("0") And Len(ServicePort.Text) > 5 Then
  384.         KeyAscii = 0
  385.         Beep
  386.     End If
  387. End Sub
  388. Sub ServicePort_LostFocus ()
  389.     On Error GoTo BadPort
  390.     Socket1.RemotePort = Val(Trim(ServicePort.Text))
  391.     ServiceName.Text = Socket1.RemoteService
  392.     Exit Sub
  393. BadPort:
  394.     ServiceName.Text = ""
  395.     ServicePort.SetFocus
  396.     Exit Sub
  397. End Sub
  398. Sub Socket1_Close ()
  399.     Socket1.Action = SOCKET_CLOSE
  400.     ActionButton.Caption = "Connect"
  401.     ActionButton.Default = True
  402.     HostName.SetFocus
  403. End Sub
  404. Sub Socket1_Connect ()
  405.     MainForm.MousePointer = 0
  406.     ActionButton.Caption = "Close"
  407.     ActionButton.Enabled = True
  408.     SocketInput.SetFocus
  409. End Sub
  410. Sub Socket1_Error (ErrCode As Integer, ErrMsg As String, Response As Integer)
  411.     If Socket1.Action = SOCKET_CONNECT Then
  412.         MsgBox ErrMsg, 0, "Connect"
  413.         Response = SOCKET_ERRIGNORE
  414.         Socket1.Action = SOCKET_CLOSE
  415.         ActionButton.Caption = "Connect"
  416.         ActionButton.Default = True
  417.         ActionButton.Enabled = True
  418.         Exit Sub
  419.     End If
  420. End Sub
  421. Sub Socket1_Read (DataLength As Integer, IsUrgent As Integer)
  422.     Socket1.RecvLen = DataLength
  423.     SocketOutput.AddItem Socket1.RecvData
  424.     SocketOutput.ListIndex = SocketOutput.ListCount - 1
  425.     SocketOutput.Selected(SocketOutput.ListIndex) = False
  426. End Sub
  427. Sub Socket2_Accept (SocketId As Integer)
  428.     Socket2.Action = SOCKET_ACCEPT
  429. End Sub
  430. Sub Socket2_Close ()
  431.     Socket2.Action = SOCKET_CLOSE
  432.     If ServerOption.Checked Then
  433.         Socket2.ReuseAddress = True
  434.         Socket2.Action = SOCKET_LISTEN
  435.     End If
  436. End Sub
  437. Sub Socket2_Read (DataLength As Integer, IsUrgent As Integer)
  438.     Socket2.RecvLen = DataLength
  439.     Socket2.SendLen = DataLength
  440.     Socket2.SendData = Socket2.RecvData
  441. End Sub
  442. Sub SocketInput_KeyPress (KeyAscii As Integer)
  443.     If KeyAscii = 13 Then
  444.         KeyAscii = 0
  445.         Socket1.SendLen = Len(SocketInput.Text) + 2
  446.         Socket1.SendData = SocketInput.Text & Chr(13) & Chr(10)
  447.         SocketInput.Text = ""
  448.     End If
  449. End Sub
  450. Sub Spin1_SpinDown ()
  451.     Dim Value As Integer
  452.     Value = Val(ServicePort.Text) - 1
  453.     If Value >= 0 Then
  454.         Socket1.RemotePort = Value
  455.         ServiceName.Text = Socket1.RemoteService
  456.         ServicePort.Text = Trim(Str(Value))
  457.     Else
  458.         Beep
  459.     End If
  460. End Sub
  461. Sub Spin1_SpinUp ()
  462.     Dim Value As Integer
  463.     Value = Val(ServicePort.Text) + 1
  464.     If Value > 0 Then
  465.         Socket1.RemotePort = Value
  466.         ServiceName.Text = Socket1.RemoteService
  467.         ServicePort.Text = Trim(Str(Value))
  468.     Else
  469.         Beep
  470.     End If
  471. End Sub
  472.