ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/host/vb_net_test/nettest.frm
Revision: 1.8
Committed: Fri Feb 23 11:25:35 2001 UTC (23 years, 9 months ago) by pjm2
Branch: MAIN
Changes since 1.7: +72 -7 lines
Log Message:
VB Timer limit was ~65000 milliseconds.
The two timers have been removed and replaced with a single timer to allow
TCP/UDP intervals greater than 65 seconds.

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 pjm2 1.8 Begin VB.Timer Timer1
18 pjm2 1.7 Left = 3840
19     Top = 120
20     End
21 pjm2 1.1 Begin VB.CommandButton Command3
22     Caption = "TCP to Filter"
23     Height = 375
24     Left = 3720
25 pjm2 1.6 TabIndex = 3
26 pjm2 1.1 Top = 2520
27     Width = 1575
28     End
29     Begin VB.TextBox Text4
30 pjm2 1.6 Height = 1575
31 pjm2 1.1 Left = 240
32     MultiLine = -1 'True
33     ScrollBars = 2 'Vertical
34 pjm2 1.6 TabIndex = 2
35 pjm2 1.1 Text = "nettest.frx":0000
36     Top = 3000
37     Width = 5055
38     End
39     Begin VB.CommandButton Command2
40     Caption = "TCP to FilterManager"
41     Height = 375
42     Left = 3360
43 pjm2 1.6 TabIndex = 1
44 pjm2 1.1 Top = 2040
45     Width = 1935
46     End
47 pjm2 1.5 Begin MSWinsockLib.Winsock TCPSock
48 pjm2 1.1 Left = 4920
49     Top = 120
50     _ExtentX = 741
51     _ExtentY = 741
52     _Version = 393216
53     End
54     Begin VB.CommandButton Command1
55     Caption = "Send UDP"
56     Height = 375
57     Left = 4320
58 pjm2 1.6 TabIndex = 0
59 pjm2 1.1 Top = 1560
60     Width = 975
61     End
62 pjm2 1.5 Begin MSWinsockLib.Winsock UDPSock
63 pjm2 1.1 Left = 4320
64     Top = 120
65     _ExtentX = 741
66     _ExtentY = 741
67     _Version = 393216
68     Protocol = 1
69     End
70 pjm2 1.8 Begin VB.Label Label4
71     Caption = "Label4"
72     Height = 255
73     Left = 1920
74     TabIndex = 8
75     Top = 1320
76     Width = 615
77     End
78     Begin VB.Label Label3
79     Caption = "Label3"
80     Height = 255
81     Left = 1920
82     TabIndex = 7
83     Top = 960
84     Width = 615
85     End
86 pjm2 1.7 Begin VB.Label Label2
87     Caption = "Label2"
88     Height = 255
89     Left = 120
90     TabIndex = 6
91     Top = 600
92     Width = 3375
93     End
94     Begin VB.Label Label1
95     Caption = "Label1"
96     Height = 255
97     Left = 120
98     TabIndex = 5
99     Top = 240
100     Width = 3375
101     End
102 pjm2 1.6 Begin VB.Label Status
103     Caption = "Status:"
104 pjm2 1.1 Height = 255
105 pjm2 1.6 Left = 120
106     TabIndex = 4
107     Top = 5280
108     Width = 5415
109 pjm2 1.1 End
110     End
111     Attribute VB_Name = "Form1"
112     Attribute VB_GlobalNameSpace = False
113     Attribute VB_Creatable = False
114     Attribute VB_PredeclaredId = True
115     Attribute VB_Exposed = False
116 pjm2 1.4 Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
117     Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
118    
119     Dim filterManagerHostname As String
120     Dim filterManagerTCPPort As Integer
121    
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 pjm2 1.7 Dim UDPUpdateTime As Integer
129     Dim TCPUpdateTime As Integer
130    
131 pjm2 1.2 Dim protocolVersion As String
132     Dim connected As Boolean
133 pjm2 1.1 Dim responseNumber As Integer
134    
135    
136     Private Sub Command1_Click()
137    
138 pjm2 1.5 ' build the contents of the XML packet.
139 pjm2 1.4 xml = "<packet></packet>"
140    
141 pjm2 1.2 ' Use the first winsock control to send a UDP packet.
142 pjm2 1.5 UDPSock.RemoteHost = filterHostname
143     UDPSock.RemotePort = filterUDPPort
144     UDPSock.SendData xml
145 pjm2 1.6 Status.Caption = "i-scream Winhost " & protocolVersion & " - UDP packet sent."
146 pjm2 1.1
147     End Sub
148    
149     Private Sub Command2_Click()
150    
151 pjm2 1.3 ' establish a TCP connection to a filtermanager
152 pjm2 1.5 TCPSock.Close
153     TCPSock.Connect filterManagerHostname, filterManagerTCPPort
154 pjm2 1.1
155     End Sub
156    
157     Private Sub Command3_Click()
158 pjm2 1.3 ' establish a TCP connection to a filter
159 pjm2 1.5 TCPSock.Close
160     TCPSock.Connect filterHostname, filterTCPPort
161 pjm2 1.1 End Sub
162    
163 pjm2 1.2 Private Sub Form_Load()
164     protocolVersion = "1.1"
165 pjm2 1.4
166 pjm2 1.6 Status.Caption = "i-scream Winhost " & protocolVersion
167    
168 pjm2 1.4 ''''TEMP
169     filterManagerHostname = "killigrew.ukc.ac.uk"
170     filterManagerTCPPort = 4567
171     Exit Sub
172     ''' ENDTEMP
173    
174     On Error GoTo iniError
175     Dim buf As String * 256
176     Dim length As Long
177     length = GetPrivateProfileString("i-scream Winhost", "FilterManager", "<no value>", buf, Len(buf), App.Path & "winhost.ini")
178     filterManagerHostname = Left$(buf, length)
179     length = GetPrivateProfileString("i-scream Winhost", "FilterManagerPort", "<no value>", buf, Len(buf), App.Path & "winhost.ini")
180     filterManagerTCPPort = Left$(buf, length)
181    
182 pjm2 1.6 Status.Caption = "i-scream Winhost " & protocolVersion & " connecting to Filter Manager"
183    
184 pjm2 1.4 Exit Sub
185    
186     iniError:
187     x = MsgBox("The i-scream Winhost could not read the correct settings from the winhost.ini file. Please correct these and try again.", 48, "Configuration not found")
188     End
189    
190     End Sub
191    
192 pjm2 1.5 Private Sub TCPSock_Connect()
193 pjm2 1.6
194     responseNumber = 0
195 pjm2 1.1
196 pjm2 1.3 ' Send something as soon as we connect to the server.
197     If connected = False Then
198     ' contact the FilterManager
199 pjm2 1.5 TCPSock.SendData "STARTCONFIG" & vbCrLf
200 pjm2 1.3 Else
201     ' Contact the Filter
202 pjm2 1.5 TCPSock.SendData "HEARTBEAT" & vbCrLf
203 pjm2 1.3 End If
204 pjm2 1.1
205     End Sub
206    
207 pjm2 1.5 Private Sub TCPSock_DataArrival(ByVal bytesTotal As Long)
208 pjm2 1.1
209     responseNumber = responseNumber + 1
210    
211     ' Get the line from the server.
212 pjm2 1.5 TCPSock.GetData response, vbString, bytesTotal
213 pjm2 1.1
214     ' Remove linefeeds and returns from the line.
215     response = Replace(response, Chr(13), "")
216     response = Replace(response, Chr(10), "")
217     Text4.Text = Text4.Text & vbCrLf & response
218    
219 pjm2 1.2 If connected = False Then
220     ' Perform TCP configuration (1.1)
221     On Error GoTo configError
222     Select Case responseNumber
223     Case 1:
224     If Not response = "OK" Then GoTo configError
225 pjm2 1.5 TCPSock.SendData "LASTMODIFIED" & vbCrLf
226 pjm2 1.2 Case 2:
227     If response = "ERROR" Then GoTo configError
228 pjm2 1.3 lastModified = response
229 pjm2 1.5 TCPSock.SendData "FILELIST" & vbCrLf
230 pjm2 1.2 Case 3:
231     If response = "ERROR" Then GoTo configError
232 pjm2 1.3 fileList = response
233 pjm2 1.5 TCPSock.SendData "UDPUpdateTime" & vbCrLf
234 pjm2 1.2 Case 4:
235     If response = "ERROR" Then GoTo configError
236 pjm2 1.7 UDPUpdateTime = response
237 pjm2 1.5 TCPSock.SendData "TCPUpdateTime" & vbCrLf
238 pjm2 1.2 Case 5:
239     If response = "ERROR" Then GoTo configError
240 pjm2 1.7 TCPUpdateTime = response
241 pjm2 1.5 TCPSock.SendData "ENDCONFIG" & vbCrLf
242 pjm2 1.2 Case 6:
243     If Not response = "OK" Then GoTo configError
244 pjm2 1.5 TCPSock.SendData "FILTER" & vbCrLf
245 pjm2 1.2 Case 7:
246     'we got a filter list here.
247     readTo = 0
248     ' get hostname
249     readTo = InStr(1, response, ";", vbBinaryCompare)
250     filterHostname = Mid(response, 1, readTo - 1)
251     response = Mid(response, readTo + 1, Len(response))
252     ' get UDP Port number
253     readTo = InStr(1, response, ";")
254     filterUDPPort = Mid(response, 1, readTo - 1)
255     response = Mid(response, readTo + 1, Len(response))
256     ' get TCP Port number
257     filterTCPPort = response
258 pjm2 1.5 TCPSock.SendData "END" & vbCrLf
259 pjm2 1.2 Case 8:
260     If Not response = "OK" Then GoTo configError
261     connected = True
262     responseNumber = 0
263 pjm2 1.5 TCPSock.Close
264 pjm2 1.2 Text4.Text = Text4.Text & vbCrLf & " <closed>"
265 pjm2 1.7 Label1.Caption = "TCP hearbeat interval: " & UDPUpdateTime
266     Label2.Caption = "UDP packet interval: " & TCPUpdateTime
267 pjm2 1.6 Status.Caption = "i-scream Winhost " & protocolVersion & " - got config okay"
268 pjm2 1.8 Label3.Caption = UDPUpdateTime
269     Label4.Caption = TCPUpdateTime
270     Timer1.Interval = 1000
271 pjm2 1.2 End Select
272     Else
273     ' Perform a heartbeat (1.1)
274     On Error GoTo heartbeatError
275     Select Case responseNumber
276     Case 1:
277 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
278 pjm2 1.5 TCPSock.SendData "CONFIG" & vbCrLf
279 pjm2 1.2 Case 2:
280 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
281 pjm2 1.5 TCPSock.SendData fileList & vbCrLf
282 pjm2 1.2 Case 3:
283 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
284 pjm2 1.5 TCPSock.SendData lastModified & vbCrLf
285 pjm2 1.2 Case 4:
286 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
287 pjm2 1.5 TCPSock.SendData "ENDHEARTBEAT" & vbCrLf
288 pjm2 1.2 Case 5:
289 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
290 pjm2 1.5 TCPSock.Close
291 pjm2 1.6 Status.Caption = "i-scream Winhost " & protocolVersion & " - heartbeat sent okay."
292 pjm2 1.2 End Select
293    
294     End If
295    
296    
297     Exit Sub
298    
299     configError:
300 pjm2 1.8 Status.Caption = "i-scream Winhost " & protocolVersion & " - FAILED to get configuration " & Err.Description
301     Exit Sub
302 pjm2 1.2 heartbeatError:
303 pjm2 1.8 Status.Caption = "i-scream Winhost " & protocolVersion & " - Heatbeat FAILED " & Err.Description
304     Exit Sub
305 pjm2 1.1 End Sub
306 pjm2 1.5
307 pjm2 1.8 Private Sub TCPTimer_Timer()
308    
309     ' establish a TCP connection to a filter
310     TCPSock.Close
311     TCPSock.Connect filterHostname, filterTCPPort
312    
313     End Sub
314    
315     Private Sub UDPTimer_Timer()
316    
317     ' build the contents of the XML packet.
318     xml = "<packet></packet>"
319    
320     ' Use the first winsock control to send a UDP packet.
321     UDPSock.RemoteHost = filterHostname
322     UDPSock.RemotePort = filterUDPPort
323     UDPSock.SendData xml
324     Status.Caption = "i-scream Winhost " & protocolVersion & " - UDP packet sent."
325    
326     End Sub
327    
328     Private Sub Timer1_Timer()
329    
330     Label3.Caption = Label3.Caption - 1
331     Label4.Caption = Label4.Caption - 1
332    
333     Status.Caption = "i-scream Winhost " & protocolVersion
334    
335     If Label3.Caption < 1 Then
336     ' build the contents of the XML packet.
337     xml = "<packet></packet>"
338    
339     ' Use the first winsock control to send a UDP packet.
340     UDPSock.RemoteHost = filterHostname
341     UDPSock.RemotePort = filterUDPPort
342     UDPSock.SendData xml
343     Status.Caption = "i-scream Winhost " & protocolVersion & " - UDP packet sent."
344     Label3.Caption = UDPUpdateTime
345     End If
346    
347     If Label4.Caption < 1 Then
348     ' establish a TCP connection to a filter
349     TCPSock.Close
350     TCPSock.Connect filterHostname, filterTCPPort
351     Label4.Caption = TCPUpdateTime
352     End If
353    
354     End Sub