home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap15 / generic.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-10-11  |  6.5 KB  |  217 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   3195
  5.    ClientLeft      =   2145
  6.    ClientTop       =   3105
  7.    ClientWidth     =   5610
  8.    Height          =   3600
  9.    Left            =   2085
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3195
  12.    ScaleWidth      =   5610
  13.    Top             =   2760
  14.    Width           =   5730
  15.    Begin Socket Socket2 
  16.       Backlog         =   1
  17.       Binary          =   -1  'True
  18.       Blocking        =   -1  'True
  19.       Broadcast       =   0   'False
  20.       BufferSize      =   0
  21.       HostAddress     =   ""
  22.       HostFile        =   ""
  23.       HostName        =   ""
  24.       Index           =   0
  25.       InLine          =   0   'False
  26.       Interval        =   0
  27.       KeepAlive       =   0   'False
  28.       Left            =   720
  29.       Linger          =   0
  30.       LocalPort       =   0
  31.       LocalService    =   ""
  32.       Peek            =   0   'False
  33.       Protocol        =   0
  34.       RecvLen         =   0
  35.       RemotePort      =   0
  36.       RemoteService   =   ""
  37.       ReuseAddress    =   0   'False
  38.       Route           =   -1  'True
  39.       SendLen         =   0
  40.       TabIndex        =   8
  41.       Timeout         =   0
  42.       Top             =   2520
  43.       Type            =   1
  44.       Urgent          =   0   'False
  45.    End
  46.    Begin Socket Socket1 
  47.       Backlog         =   1
  48.       Binary          =   -1  'True
  49.       Blocking        =   -1  'True
  50.       Broadcast       =   0   'False
  51.       BufferSize      =   0
  52.       HostAddress     =   ""
  53.       HostFile        =   ""
  54.       HostName        =   ""
  55.       InLine          =   0   'False
  56.       Interval        =   0
  57.       KeepAlive       =   0   'False
  58.       Left            =   120
  59.       Linger          =   0
  60.       LocalPort       =   0
  61.       LocalService    =   ""
  62.       Peek            =   0   'False
  63.       Protocol        =   0
  64.       RecvLen         =   0
  65.       RemotePort      =   0
  66.       RemoteService   =   ""
  67.       ReuseAddress    =   0   'False
  68.       Route           =   -1  'True
  69.       SendLen         =   0
  70.       TabIndex        =   7
  71.       Timeout         =   0
  72.       Top             =   2520
  73.       Type            =   1
  74.       Urgent          =   0   'False
  75.    End
  76.    Begin CommandButton Command1 
  77.       Caption         =   "&Connect"
  78.       Height          =   375
  79.       Left            =   2160
  80.       TabIndex        =   6
  81.       Top             =   2520
  82.       Width           =   1215
  83.    End
  84.    Begin TextBox Text3 
  85.       Enabled         =   0   'False
  86.       Height          =   855
  87.       Left            =   960
  88.       TabIndex        =   5
  89.       Top             =   1320
  90.       Width           =   3855
  91.    End
  92.    Begin TextBox Text2 
  93.       Enabled         =   0   'False
  94.       Height          =   285
  95.       Left            =   960
  96.       TabIndex        =   3
  97.       Top             =   840
  98.       Width           =   3855
  99.    End
  100.    Begin TextBox Text1 
  101.       Height          =   285
  102.       Left            =   960
  103.       TabIndex        =   1
  104.       Top             =   360
  105.       Width           =   2055
  106.    End
  107.    Begin Label Label3 
  108.       AutoSize        =   -1  'True
  109.       Caption         =   "Reply:"
  110.       Height          =   195
  111.       Left            =   360
  112.       TabIndex        =   4
  113.       Top             =   1320
  114.       Width           =   555
  115.    End
  116.    Begin Label Label2 
  117.       AutoSize        =   -1  'True
  118.       Caption         =   "Send:"
  119.       Height          =   195
  120.       Left            =   360
  121.       TabIndex        =   2
  122.       Top             =   840
  123.       Width           =   510
  124.    End
  125.    Begin Label Label1 
  126.       AutoSize        =   -1  'True
  127.       Caption         =   "Host:"
  128.       Height          =   195
  129.       Left            =   360
  130.       TabIndex        =   0
  131.       Top             =   360
  132.       Width           =   465
  133.    End
  134. Option Explicit
  135. Dim LastSocket As Integer
  136. Sub Command1_Click ()
  137.     If Socket1.Connected Then
  138.         Socket1.Action = SOCKET_CLOSE
  139.         Text1.Enabled = True
  140.         Command1.Enabled = True
  141.         Command1.Caption = "Connect"
  142.     Else
  143.         Command1.Enabled = False
  144.         Socket1.HostName = Trim$(Text1.Text)
  145.         Socket1.LocalPort = IPPORT_ANY
  146.         Socket1.RemotePort = IPPORT_ECHO
  147.         Socket1.Action = SOCKET_CONNECT
  148.     End If
  149. End Sub
  150. Sub Form_Load ()
  151.     Socket1.AddressFamily = AF_INET
  152.     Socket1.Protocol = IPPROTO_IP
  153.     Socket1.Type = SOCK_STREAM
  154.     Socket1.Binary = False
  155.     Socket1.BufferSize = 1024
  156.     Socket1.Blocking = False
  157.     Socket2(0).AddressFamily = AF_INET
  158.     Socket2(0).Protocol = IPPROTO_IP
  159.     Socket2(0).Type = SOCK_STREAM
  160.     Socket2(0).Blocking = False
  161.     Socket2(0).LocalPort = IPPORT_ECHO
  162.     Socket2(0).Action = SOCKET_LISTEN
  163.     LastSocket = 0
  164. End Sub
  165. Sub Form_Unload (Cancel As Integer)
  166.     Dim I As Integer
  167.     If Socket1.Connected Then Socket1.Action = SOCKET_CLOSE
  168.     If Socket2(0).Listening Then Socket2(0).Action = SOCKET_CLOSE
  169.     For I = 1 To LastSocket
  170.         If Socket2(I).Connected Then Socket2(I).Action = SOCKET_CLOSE
  171.     Next I
  172.     End
  173. End Sub
  174. Sub Socket1_Connect ()
  175.     Text1.Enabled = False
  176.     Text2.Enabled = True
  177.     Text3.Enabled = True
  178.     Command1.Caption = "Disconnect"
  179.     Command1.Enabled = True
  180. End Sub
  181. Sub Socket1_Read (DataLength As Integer, IsUrgent As Integer)
  182.     Socket1.RecvLen = DataLength
  183.     Text3.Text = Socket1.RecvData
  184. End Sub
  185. Sub Socket2_Accept (Index As Integer, SocketId As Integer)
  186.     Dim I As Integer
  187.     For I = 1 To LastSocket
  188.         If Not Socket2(I).Connected Then Exit For
  189.     Next I
  190.     If I > LastSocket Then
  191.         LastSocket = LastSocket + 1: I = LastSocket
  192.         Load Socket2(I)
  193.     End If
  194.     Socket2(I).AddressFamily = AF_INET
  195.     Socket2(I).Protocol = IPPROTO_IP
  196.     Socket2(I).Type = SOCK_STREAM
  197.     Socket2(I).Binary = True
  198.     Socket2(I).BufferSize = 1024
  199.     Socket2(I).Blocking = False
  200.     Socket2(I).Accept = SocketId
  201. End Sub
  202. Sub Socket2_Close (Index As Integer)
  203.     Socket2(Index).Action = SOCKET_CLOSE
  204. End Sub
  205. Sub Socket2_Read (Index As Integer, DataLength As Integer, IsUrgent As Integer)
  206.     Socket2(Index).RecvLen = DataLength
  207.     Socket2(Index).SendLen = DataLength
  208.     Socket2(Index).SendData = Socket2(Index).RecvData
  209. End Sub
  210. Sub Text2_KeyPress (KeyAscii As Integer)
  211.     If KeyAscii = 13 Then
  212.         Socket1.SendLen = Len(Text2.Text)
  213.         Socket1.SendData = Text2.Text
  214.         KeyAscii = 0: Text2.Text = ""
  215.     End If
  216. End Sub
  217.