ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/host/vb_net_test/nettest.frm
Revision: 1.3
Committed: Fri Feb 23 10:07:55 2001 UTC (23 years, 8 months ago) by pjm2
Branch: MAIN
Changes since 1.2: +29 -17 lines
Log Message:
Implemented version 1.1 of the heartbeat protocol.

File Contents

# User Rev Content
1 pjm2 1.1 VERSION 5.00
2     Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
3     Begin VB.Form Form1
4     BorderStyle = 3 'Fixed Dialog
5     Caption = "TCP/UDP Test program"
6     ClientHeight = 5655
7     ClientLeft = 45
8     ClientTop = 330
9     ClientWidth = 5670
10     LinkTopic = "Form1"
11     MaxButton = 0 'False
12     MinButton = 0 'False
13     ScaleHeight = 5655
14     ScaleWidth = 5670
15     ShowInTaskbar = 0 'False
16     StartUpPosition = 3 'Windows Default
17     Begin VB.CommandButton Command3
18     Caption = "TCP to Filter"
19     Height = 375
20     Left = 3720
21     TabIndex = 9
22     Top = 2520
23     Width = 1575
24     End
25     Begin VB.TextBox Text4
26     Height = 2535
27     Left = 240
28     MultiLine = -1 'True
29     ScrollBars = 2 'Vertical
30     TabIndex = 8
31     Text = "nettest.frx":0000
32     Top = 3000
33     Width = 5055
34     End
35     Begin VB.CommandButton Command2
36     Caption = "TCP to FilterManager"
37     Height = 375
38     Left = 3360
39     TabIndex = 7
40     Top = 2040
41     Width = 1935
42     End
43     Begin MSWinsockLib.Winsock Winsock2
44     Left = 4920
45     Top = 120
46     _ExtentX = 741
47     _ExtentY = 741
48     _Version = 393216
49     End
50     Begin VB.TextBox Text3
51     Height = 285
52     Left = 1680
53     TabIndex = 5
54     Text = "killigrew.ukc.ac.uk"
55     Top = 1560
56     Width = 2535
57     End
58     Begin VB.TextBox Text2
59     Height = 285
60     Left = 1680
61     TabIndex = 3
62     Text = "4567"
63     Top = 1920
64     Width = 855
65     End
66     Begin VB.CommandButton Command1
67     Caption = "Send UDP"
68     Height = 375
69     Left = 4320
70     TabIndex = 2
71     Top = 1560
72     Width = 975
73     End
74     Begin VB.TextBox Text1
75     Height = 855
76     Left = 360
77     TabIndex = 0
78     Text = "<packet></packet>"
79     Top = 600
80     Width = 4935
81     End
82     Begin MSWinsockLib.Winsock Winsock1
83     Left = 4320
84     Top = 120
85     _ExtentX = 741
86     _ExtentY = 741
87     _Version = 393216
88     Protocol = 1
89     End
90     Begin VB.Label Label3
91     Alignment = 1 'Right Justify
92     Caption = "Destination:"
93     Height = 255
94     Left = 360
95     TabIndex = 6
96     Top = 1560
97     Width = 1215
98     End
99     Begin VB.Label Label2
100     Alignment = 1 'Right Justify
101     Caption = "Port:"
102     Height = 255
103     Left = 360
104     TabIndex = 4
105     Top = 1920
106     Width = 1215
107     End
108     Begin VB.Label Label1
109     Caption = "Packet contents"
110     Height = 255
111     Left = 360
112     TabIndex = 1
113     Top = 360
114     Width = 2895
115     End
116     End
117     Attribute VB_Name = "Form1"
118     Attribute VB_GlobalNameSpace = False
119     Attribute VB_Creatable = False
120     Attribute VB_PredeclaredId = True
121     Attribute VB_Exposed = False
122 pjm2 1.2 Dim filterHostname As String
123 pjm2 1.3 Dim filterTCPPort As Integer
124     Dim filterUDPPort As Integer
125     Dim fileList As String
126     Dim lastModified As String
127 pjm2 1.2
128     Dim protocolVersion As String
129     Dim connected As Boolean
130 pjm2 1.1 Dim responseNumber As Integer
131    
132    
133     Private Sub Command1_Click()
134    
135 pjm2 1.2 ' Use the first winsock control to send a UDP packet.
136 pjm2 1.1 Winsock1.RemoteHost = Text3.Text
137     Winsock1.RemotePort = Text2.Text
138     Winsock1.SendData Text1.Text
139    
140     End Sub
141    
142     Private Sub Command2_Click()
143    
144 pjm2 1.3 ' establish a TCP connection to a filtermanager
145 pjm2 1.1 Winsock2.Close
146     Winsock2.Connect Text3.Text, Text2.Text
147    
148     End Sub
149    
150     Private Sub Command3_Click()
151 pjm2 1.3 ' establish a TCP connection to a filter
152     Winsock2.Close
153     Winsock2.Connect filterHostname, filterTCPPort
154 pjm2 1.1 End Sub
155    
156 pjm2 1.2 Private Sub Form_Load()
157     protocolVersion = "1.1"
158     End Sub
159    
160 pjm2 1.1 Private Sub Winsock2_Connect()
161    
162     responseNumber = 0
163    
164 pjm2 1.3 ' Send something as soon as we connect to the server.
165     If connected = False Then
166     ' contact the FilterManager
167     Winsock2.SendData "STARTCONFIG" & vbCrLf
168     Else
169     ' Contact the Filter
170     Winsock2.SendData "HEARTBEAT" & vbCrLf
171     End If
172 pjm2 1.1
173     End Sub
174    
175     Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
176    
177     responseNumber = responseNumber + 1
178    
179     ' Get the line from the server.
180     Winsock2.GetData response, vbString, bytesTotal
181    
182     ' Remove linefeeds and returns from the line.
183     response = Replace(response, Chr(13), "")
184     response = Replace(response, Chr(10), "")
185     Text4.Text = Text4.Text & vbCrLf & response
186    
187 pjm2 1.2 If connected = False Then
188     ' Perform TCP configuration (1.1)
189     On Error GoTo configError
190     Select Case responseNumber
191     Case 1:
192     If Not response = "OK" Then GoTo configError
193     Winsock2.SendData "LASTMODIFIED" & vbCrLf
194     Case 2:
195     If response = "ERROR" Then GoTo configError
196 pjm2 1.3 lastModified = response
197 pjm2 1.2 Winsock2.SendData "FILELIST" & vbCrLf
198     Case 3:
199     If response = "ERROR" Then GoTo configError
200 pjm2 1.3 fileList = response
201 pjm2 1.2 Winsock2.SendData "UDPUpdateTime" & vbCrLf
202     Case 4:
203     If response = "ERROR" Then GoTo configError
204     Winsock2.SendData "TCPUpdateTime" & vbCrLf
205     Case 5:
206     If response = "ERROR" Then GoTo configError
207     Winsock2.SendData "ENDCONFIG" & vbCrLf
208     Case 6:
209     If Not response = "OK" Then GoTo configError
210     Winsock2.SendData "FILTER" & vbCrLf
211     Case 7:
212     'we got a filter list here.
213     readTo = 0
214     ' get hostname
215     readTo = InStr(1, response, ";", vbBinaryCompare)
216     filterHostname = Mid(response, 1, readTo - 1)
217     response = Mid(response, readTo + 1, Len(response))
218     ' get UDP Port number
219     readTo = InStr(1, response, ";")
220     filterUDPPort = Mid(response, 1, readTo - 1)
221     response = Mid(response, readTo + 1, Len(response))
222     ' get TCP Port number
223     filterTCPPort = response
224     Winsock2.SendData "END" & vbCrLf
225     Case 8:
226     If Not response = "OK" Then GoTo configError
227     connected = True
228     responseNumber = 0
229     Winsock2.Close
230     Text4.Text = Text4.Text & vbCrLf & " <closed>"
231     x = MsgBox("got config okay")
232     End Select
233     Else
234     ' Perform a heartbeat (1.1)
235     On Error GoTo heartbeatError
236     Select Case responseNumber
237     Case 1:
238 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
239     Winsock2.SendData "CONFIG" & vbCrLf
240 pjm2 1.2 Case 2:
241 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
242     Winsock2.SendData fileList & vbCrLf
243 pjm2 1.2 Case 3:
244 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
245     Winsock2.SendData lastModified & vbCrLf
246 pjm2 1.2 Case 4:
247 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
248     Winsock2.SendData "ENDHEARTBEAT" & vbCrLf
249 pjm2 1.2 Case 5:
250 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
251     Winsock2.Close
252     x = MsgBox("heartbeat sent okay.")
253 pjm2 1.2 End Select
254    
255     End If
256    
257    
258     Exit Sub
259    
260     configError:
261     x = MsgBox("error doing configuration")
262     heartbeatError:
263 pjm2 1.1
264     End Sub