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" |
4 |
> |
BorderStyle = 4 'Fixed ToolWindow |
5 |
> |
Caption = "i-scream Winhost" |
6 |
|
ClientHeight = 5655 |
7 |
|
ClientLeft = 45 |
8 |
< |
ClientTop = 330 |
8 |
> |
ClientTop = 285 |
9 |
|
ClientWidth = 5670 |
10 |
|
LinkTopic = "Form1" |
11 |
|
MaxButton = 0 'False |
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 = 5 |
22 |
< |
Top = 2520 |
23 |
< |
Width = 1575 |
17 |
> |
Begin VB.Timer Timer1 |
18 |
> |
Left = 4200 |
19 |
> |
Top = 1200 |
20 |
|
End |
21 |
|
Begin VB.TextBox Text4 |
22 |
< |
Height = 2535 |
22 |
> |
Height = 1575 |
23 |
|
Left = 240 |
24 |
|
MultiLine = -1 'True |
25 |
|
ScrollBars = 2 'Vertical |
26 |
< |
TabIndex = 4 |
26 |
> |
TabIndex = 1 |
27 |
|
Text = "nettest.frx":0000 |
28 |
|
Top = 3000 |
29 |
|
Width = 5055 |
30 |
|
End |
31 |
< |
Begin VB.CommandButton Command2 |
32 |
< |
Caption = "TCP to FilterManager" |
33 |
< |
Height = 375 |
34 |
< |
Left = 3360 |
35 |
< |
TabIndex = 3 |
40 |
< |
Top = 2040 |
41 |
< |
Width = 1935 |
42 |
< |
End |
43 |
< |
Begin MSWinsockLib.Winsock Winsock2 |
44 |
< |
Left = 4920 |
31 |
> |
Begin VB.CommandButton Reconfigure |
32 |
> |
Caption = "Reconfigure with FilterManager" |
33 |
> |
Height = 495 |
34 |
> |
Left = 120 |
35 |
> |
TabIndex = 0 |
36 |
|
Top = 120 |
37 |
+ |
Width = 2895 |
38 |
+ |
End |
39 |
+ |
Begin MSWinsockLib.Winsock TCPSock |
40 |
+ |
Left = 5160 |
41 |
+ |
Top = 1200 |
42 |
|
_ExtentX = 741 |
43 |
|
_ExtentY = 741 |
44 |
|
_Version = 393216 |
45 |
|
End |
46 |
< |
Begin VB.CommandButton Command1 |
47 |
< |
Caption = "Send UDP" |
48 |
< |
Height = 375 |
53 |
< |
Left = 4320 |
54 |
< |
TabIndex = 2 |
55 |
< |
Top = 1560 |
56 |
< |
Width = 975 |
57 |
< |
End |
58 |
< |
Begin VB.TextBox Text1 |
59 |
< |
Height = 855 |
60 |
< |
Left = 360 |
61 |
< |
TabIndex = 0 |
62 |
< |
Text = "<packet></packet>" |
63 |
< |
Top = 600 |
64 |
< |
Width = 4935 |
65 |
< |
End |
66 |
< |
Begin MSWinsockLib.Winsock Winsock1 |
67 |
< |
Left = 4320 |
68 |
< |
Top = 120 |
46 |
> |
Begin MSWinsockLib.Winsock UDPSock |
47 |
> |
Left = 4680 |
48 |
> |
Top = 1200 |
49 |
|
_ExtentX = 741 |
50 |
|
_ExtentY = 741 |
51 |
|
_Version = 393216 |
52 |
|
Protocol = 1 |
53 |
|
End |
54 |
+ |
Begin VB.Label Label2 |
55 |
+ |
Alignment = 1 'Right Justify |
56 |
+ |
Caption = "Next heartbeat:" |
57 |
+ |
Height = 255 |
58 |
+ |
Left = 3360 |
59 |
+ |
TabIndex = 6 |
60 |
+ |
Top = 480 |
61 |
+ |
Width = 1455 |
62 |
+ |
End |
63 |
|
Begin VB.Label Label1 |
64 |
< |
Caption = "Packet contents" |
64 |
> |
Alignment = 1 'Right Justify |
65 |
> |
Caption = "Next UDP packet:" |
66 |
|
Height = 255 |
67 |
< |
Left = 360 |
68 |
< |
TabIndex = 1 |
69 |
< |
Top = 360 |
70 |
< |
Width = 2895 |
67 |
> |
Left = 3360 |
68 |
> |
TabIndex = 5 |
69 |
> |
Top = 120 |
70 |
> |
Width = 1455 |
71 |
|
End |
72 |
+ |
Begin VB.Label Label4 |
73 |
+ |
BorderStyle = 1 'Fixed Single |
74 |
+ |
Caption = "0" |
75 |
+ |
Height = 255 |
76 |
+ |
Left = 4920 |
77 |
+ |
TabIndex = 4 |
78 |
+ |
Top = 480 |
79 |
+ |
Width = 615 |
80 |
+ |
End |
81 |
+ |
Begin VB.Label Label3 |
82 |
+ |
BorderStyle = 1 'Fixed Single |
83 |
+ |
Caption = "0" |
84 |
+ |
Height = 255 |
85 |
+ |
Left = 4920 |
86 |
+ |
TabIndex = 3 |
87 |
+ |
Top = 120 |
88 |
+ |
Width = 615 |
89 |
+ |
End |
90 |
+ |
Begin VB.Label Status |
91 |
+ |
Caption = "Status:" |
92 |
+ |
Height = 255 |
93 |
+ |
Left = 120 |
94 |
+ |
TabIndex = 2 |
95 |
+ |
Top = 840 |
96 |
+ |
Width = 5415 |
97 |
+ |
End |
98 |
|
End |
99 |
|
Attribute VB_Name = "Form1" |
100 |
|
Attribute VB_GlobalNameSpace = False |
113 |
|
Dim fileList As String |
114 |
|
Dim lastModified As String |
115 |
|
|
116 |
+ |
Dim UDPUpdateTime As Integer |
117 |
+ |
Dim TCPUpdateTime As Integer |
118 |
+ |
|
119 |
|
Dim protocolVersion As String |
120 |
|
Dim connected As Boolean |
121 |
|
Dim responseNumber As Integer |
123 |
|
|
124 |
|
Private Sub Command1_Click() |
125 |
|
|
126 |
+ |
' build the contents of the XML packet. |
127 |
|
xml = "<packet></packet>" |
128 |
|
|
129 |
|
' Use the first winsock control to send a UDP packet. |
130 |
< |
Winsock1.RemoteHost = filterHostname |
131 |
< |
Winsock1.RemotePort = filterUDPPort |
132 |
< |
Winsock1.SendData xml |
130 |
> |
UDPSock.RemoteHost = filterHostname |
131 |
> |
UDPSock.RemotePort = filterUDPPort |
132 |
> |
UDPSock.SendData xml |
133 |
> |
Status.Caption = "i-scream Winhost " & protocolVersion & " - UDP packet sent." |
134 |
|
|
135 |
|
End Sub |
136 |
|
|
116 |
– |
Private Sub Command2_Click() |
117 |
– |
|
118 |
– |
' establish a TCP connection to a filtermanager |
119 |
– |
Winsock2.Close |
120 |
– |
Winsock2.Connect filterManagerHostname, filterManagerTCPPort |
137 |
|
|
122 |
– |
End Sub |
123 |
– |
|
138 |
|
Private Sub Command3_Click() |
139 |
|
' establish a TCP connection to a filter |
140 |
< |
Winsock2.Close |
141 |
< |
Winsock2.Connect filterHostname, filterTCPPort |
140 |
> |
TCPSock.Close |
141 |
> |
TCPSock.Connect filterHostname, filterTCPPort |
142 |
|
End Sub |
143 |
|
|
144 |
|
Private Sub Form_Load() |
145 |
|
protocolVersion = "1.1" |
146 |
+ |
|
147 |
+ |
Status.Caption = "Loading" |
148 |
+ |
Form1.Caption = "i-scream Winhost " & protocolVersion |
149 |
|
|
150 |
|
''''TEMP |
151 |
|
filterManagerHostname = "killigrew.ukc.ac.uk" |
152 |
|
filterManagerTCPPort = 4567 |
153 |
+ |
Reconfigure_Click |
154 |
|
Exit Sub |
155 |
|
''' ENDTEMP |
156 |
|
|
162 |
|
length = GetPrivateProfileString("i-scream Winhost", "FilterManagerPort", "<no value>", buf, Len(buf), App.Path & "winhost.ini") |
163 |
|
filterManagerTCPPort = Left$(buf, length) |
164 |
|
|
165 |
+ |
Status.Caption = "Connecting to Filter Manager" |
166 |
+ |
|
167 |
|
Exit Sub |
168 |
|
|
169 |
|
iniError: |
172 |
|
|
173 |
|
End Sub |
174 |
|
|
175 |
< |
Private Sub Label2_Click() |
175 |
> |
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) |
176 |
> |
x = MsgBox("Are you sure you want to shut down the Winhost?", vbYesNo, "i-scream Winhost") |
177 |
> |
If x = 7 Then |
178 |
> |
Cancel = True |
179 |
> |
End If |
180 |
|
|
181 |
|
End Sub |
182 |
|
|
183 |
< |
Private Sub Winsock2_Connect() |
184 |
< |
|
185 |
< |
responseNumber = 0 |
183 |
> |
Private Sub Reconfigure_Click() |
184 |
> |
' establish a TCP connection to a filtermanager |
185 |
> |
connected = False |
186 |
> |
TCPSock.Close |
187 |
> |
TCPSock.Connect filterManagerHostname, filterManagerTCPPort |
188 |
> |
End Sub |
189 |
> |
|
190 |
> |
Private Sub TCPSock_Connect() |
191 |
> |
|
192 |
> |
responseNumber = 0 |
193 |
|
|
194 |
|
' Send something as soon as we connect to the server. |
195 |
|
If connected = False Then |
196 |
|
' contact the FilterManager |
197 |
< |
Winsock2.SendData "STARTCONFIG" & vbCrLf |
197 |
> |
TCPSock.SendData "STARTCONFIG" & vbCrLf |
198 |
|
Else |
199 |
|
' Contact the Filter |
200 |
< |
Winsock2.SendData "HEARTBEAT" & vbCrLf |
200 |
> |
TCPSock.SendData "HEARTBEAT" & vbCrLf |
201 |
|
End If |
202 |
|
|
203 |
|
End Sub |
204 |
|
|
205 |
< |
Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long) |
205 |
> |
Private Sub TCPSock_DataArrival(ByVal bytesTotal As Long) |
206 |
|
|
207 |
|
responseNumber = responseNumber + 1 |
208 |
|
|
209 |
|
' Get the line from the server. |
210 |
< |
Winsock2.GetData response, vbString, bytesTotal |
210 |
> |
TCPSock.GetData response, vbString, bytesTotal |
211 |
|
|
212 |
|
' Remove linefeeds and returns from the line. |
213 |
|
response = Replace(response, Chr(13), "") |
220 |
|
Select Case responseNumber |
221 |
|
Case 1: |
222 |
|
If Not response = "OK" Then GoTo configError |
223 |
< |
Winsock2.SendData "LASTMODIFIED" & vbCrLf |
223 |
> |
TCPSock.SendData "LASTMODIFIED" & vbCrLf |
224 |
|
Case 2: |
225 |
|
If response = "ERROR" Then GoTo configError |
226 |
|
lastModified = response |
227 |
< |
Winsock2.SendData "FILELIST" & vbCrLf |
227 |
> |
TCPSock.SendData "FILELIST" & vbCrLf |
228 |
|
Case 3: |
229 |
|
If response = "ERROR" Then GoTo configError |
230 |
|
fileList = response |
231 |
< |
Winsock2.SendData "UDPUpdateTime" & vbCrLf |
231 |
> |
TCPSock.SendData "UDPUpdateTime" & vbCrLf |
232 |
|
Case 4: |
233 |
|
If response = "ERROR" Then GoTo configError |
234 |
< |
Winsock2.SendData "TCPUpdateTime" & vbCrLf |
234 |
> |
UDPUpdateTime = response |
235 |
> |
TCPSock.SendData "TCPUpdateTime" & vbCrLf |
236 |
|
Case 5: |
237 |
|
If response = "ERROR" Then GoTo configError |
238 |
< |
Winsock2.SendData "ENDCONFIG" & vbCrLf |
238 |
> |
TCPUpdateTime = response |
239 |
> |
TCPSock.SendData "ENDCONFIG" & vbCrLf |
240 |
|
Case 6: |
241 |
|
If Not response = "OK" Then GoTo configError |
242 |
< |
Winsock2.SendData "FILTER" & vbCrLf |
242 |
> |
TCPSock.SendData "FILTER" & vbCrLf |
243 |
|
Case 7: |
244 |
|
'we got a filter list here. |
245 |
|
readTo = 0 |
253 |
|
response = Mid(response, readTo + 1, Len(response)) |
254 |
|
' get TCP Port number |
255 |
|
filterTCPPort = response |
256 |
< |
Winsock2.SendData "END" & vbCrLf |
256 |
> |
TCPSock.SendData "END" & vbCrLf |
257 |
|
Case 8: |
258 |
|
If Not response = "OK" Then GoTo configError |
259 |
|
connected = True |
260 |
|
responseNumber = 0 |
261 |
< |
Winsock2.Close |
261 |
> |
TCPSock.Close |
262 |
|
Text4.Text = Text4.Text & vbCrLf & " <closed>" |
263 |
< |
x = MsgBox("got config okay") |
263 |
> |
Status.Caption = "Configuration successful" |
264 |
> |
Label3.Caption = UDPUpdateTime |
265 |
> |
Label4.Caption = TCPUpdateTime |
266 |
> |
Timer1.Interval = 1000 |
267 |
|
End Select |
268 |
|
Else |
269 |
|
' Perform a heartbeat (1.1) |
271 |
|
Select Case responseNumber |
272 |
|
Case 1: |
273 |
|
If Not response = "OK" Then GoTo heartbeatError |
274 |
< |
Winsock2.SendData "CONFIG" & vbCrLf |
274 |
> |
TCPSock.SendData "CONFIG" & vbCrLf |
275 |
|
Case 2: |
276 |
|
If Not response = "OK" Then GoTo heartbeatError |
277 |
< |
Winsock2.SendData fileList & vbCrLf |
277 |
> |
TCPSock.SendData fileList & vbCrLf |
278 |
|
Case 3: |
279 |
|
If Not response = "OK" Then GoTo heartbeatError |
280 |
< |
Winsock2.SendData lastModified & vbCrLf |
280 |
> |
TCPSock.SendData lastModified & vbCrLf |
281 |
|
Case 4: |
282 |
|
If Not response = "OK" Then GoTo heartbeatError |
283 |
< |
Winsock2.SendData "ENDHEARTBEAT" & vbCrLf |
283 |
> |
TCPSock.SendData "ENDHEARTBEAT" & vbCrLf |
284 |
|
Case 5: |
285 |
|
If Not response = "OK" Then GoTo heartbeatError |
286 |
< |
Winsock2.Close |
287 |
< |
x = MsgBox("heartbeat sent okay.") |
286 |
> |
TCPSock.Close |
287 |
> |
Status.Caption = "Heartbeat sent successfully." |
288 |
|
End Select |
289 |
|
|
290 |
|
End If |
293 |
|
Exit Sub |
294 |
|
|
295 |
|
configError: |
296 |
< |
x = MsgBox("error doing configuration") |
296 |
> |
Status.Caption = "FAILED to get configuration" |
297 |
> |
Exit Sub |
298 |
|
heartbeatError: |
299 |
< |
x = MsgBox("error doing configuration") |
299 |
> |
Status.Caption = "Heatbeat FAILED" |
300 |
> |
Exit Sub |
301 |
> |
End Sub |
302 |
> |
|
303 |
> |
Private Sub Timer1_Timer() |
304 |
> |
|
305 |
> |
Label3.Caption = Label3.Caption - 1 |
306 |
> |
Label4.Caption = Label4.Caption - 1 |
307 |
> |
|
308 |
> |
Status.Caption = "" |
309 |
> |
|
310 |
> |
If Label3.Caption < 1 Then |
311 |
> |
' build the contents of the XML packet. |
312 |
> |
xml = "<packet></packet>" |
313 |
> |
|
314 |
> |
' Use the first winsock control to send a UDP packet. |
315 |
> |
UDPSock.RemoteHost = filterHostname |
316 |
> |
UDPSock.RemotePort = filterUDPPort |
317 |
> |
UDPSock.SendData xml |
318 |
> |
Status.Caption = "UDP packet sent" |
319 |
> |
Label3.Caption = UDPUpdateTime |
320 |
> |
End If |
321 |
> |
|
322 |
> |
If Label4.Caption < 1 Then |
323 |
> |
' establish a TCP connection to a filter |
324 |
> |
TCPSock.Close |
325 |
> |
TCPSock.Connect filterHostname, filterTCPPort |
326 |
> |
Label4.Caption = TCPUpdateTime |
327 |
> |
End If |
328 |
> |
|
329 |
|
End Sub |