ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/host/vb_net_test/nettest.frm
Revision: 1.11
Committed: Fri Feb 23 11:56:43 2001 UTC (23 years, 8 months ago) by pjm2
Branch: MAIN
Changes since 1.10: +33 -2 lines
Log Message:
Program can now be minimised to the system tray ;)

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 pjm2 1.11 Object = "{33155A3D-0CE0-11D1-A6B4-444553540000}#1.0#0"; "SysTray.ocx"
4 pjm2 1.1 Begin VB.Form Form1
5 pjm2 1.10 BorderStyle = 4 'Fixed ToolWindow
6     Caption = "i-scream Winhost"
7 pjm2 1.1 ClientHeight = 5655
8     ClientLeft = 45
9 pjm2 1.10 ClientTop = 285
10 pjm2 1.1 ClientWidth = 5670
11     LinkTopic = "Form1"
12     MaxButton = 0 'False
13     ScaleHeight = 5655
14     ScaleWidth = 5670
15     ShowInTaskbar = 0 'False
16     StartUpPosition = 3 'Windows Default
17 pjm2 1.11 Begin VB.CommandButton Hide
18     Caption = "Hide"
19     Height = 495
20     Left = 1800
21     TabIndex = 7
22     Top = 2160
23     Width = 1215
24     End
25     Begin SysTray.SystemTray SystemTray
26     Left = 3600
27     Top = 1200
28     _ExtentX = 847
29     _ExtentY = 847
30     SysTrayText = "i-scream Winhost"
31     IconFile = 0
32     End
33 pjm2 1.8 Begin VB.Timer Timer1
34 pjm2 1.10 Left = 4200
35     Top = 1200
36 pjm2 1.1 End
37     Begin VB.TextBox Text4
38 pjm2 1.6 Height = 1575
39 pjm2 1.1 Left = 240
40     MultiLine = -1 'True
41     ScrollBars = 2 'Vertical
42 pjm2 1.10 TabIndex = 1
43 pjm2 1.1 Text = "nettest.frx":0000
44     Top = 3000
45     Width = 5055
46     End
47 pjm2 1.10 Begin VB.CommandButton Reconfigure
48     Caption = "Reconfigure with FilterManager"
49     Height = 495
50     Left = 120
51     TabIndex = 0
52     Top = 120
53     Width = 2895
54 pjm2 1.1 End
55 pjm2 1.5 Begin MSWinsockLib.Winsock TCPSock
56 pjm2 1.10 Left = 5160
57     Top = 1200
58 pjm2 1.1 _ExtentX = 741
59     _ExtentY = 741
60     _Version = 393216
61     End
62 pjm2 1.5 Begin MSWinsockLib.Winsock UDPSock
63 pjm2 1.10 Left = 4680
64     Top = 1200
65 pjm2 1.1 _ExtentX = 741
66     _ExtentY = 741
67     _Version = 393216
68     Protocol = 1
69     End
70 pjm2 1.9 Begin VB.Label Label2
71     Alignment = 1 'Right Justify
72     Caption = "Next heartbeat:"
73 pjm2 1.8 Height = 255
74 pjm2 1.10 Left = 3360
75     TabIndex = 6
76 pjm2 1.9 Top = 480
77     Width = 1455
78 pjm2 1.8 End
79 pjm2 1.9 Begin VB.Label Label1
80     Alignment = 1 'Right Justify
81     Caption = "Next UDP packet:"
82 pjm2 1.8 Height = 255
83 pjm2 1.10 Left = 3360
84     TabIndex = 5
85 pjm2 1.9 Top = 120
86     Width = 1455
87 pjm2 1.8 End
88 pjm2 1.9 Begin VB.Label Label4
89 pjm2 1.10 BorderStyle = 1 'Fixed Single
90 pjm2 1.9 Caption = "0"
91 pjm2 1.7 Height = 255
92 pjm2 1.10 Left = 4920
93     TabIndex = 4
94 pjm2 1.9 Top = 480
95     Width = 615
96 pjm2 1.7 End
97 pjm2 1.9 Begin VB.Label Label3
98 pjm2 1.10 BorderStyle = 1 'Fixed Single
99 pjm2 1.9 Caption = "0"
100 pjm2 1.7 Height = 255
101 pjm2 1.10 Left = 4920
102     TabIndex = 3
103 pjm2 1.9 Top = 120
104     Width = 615
105 pjm2 1.7 End
106 pjm2 1.6 Begin VB.Label Status
107     Caption = "Status:"
108 pjm2 1.1 Height = 255
109 pjm2 1.6 Left = 120
110 pjm2 1.10 TabIndex = 2
111     Top = 840
112 pjm2 1.6 Width = 5415
113 pjm2 1.1 End
114     End
115     Attribute VB_Name = "Form1"
116     Attribute VB_GlobalNameSpace = False
117     Attribute VB_Creatable = False
118     Attribute VB_PredeclaredId = True
119     Attribute VB_Exposed = False
120 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
121     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
122    
123     Dim filterManagerHostname As String
124     Dim filterManagerTCPPort As Integer
125    
126 pjm2 1.2 Dim filterHostname As String
127 pjm2 1.3 Dim filterTCPPort As Integer
128     Dim filterUDPPort As Integer
129     Dim fileList As String
130     Dim lastModified As String
131 pjm2 1.2
132 pjm2 1.7 Dim UDPUpdateTime As Integer
133     Dim TCPUpdateTime As Integer
134    
135 pjm2 1.2 Dim protocolVersion As String
136     Dim connected As Boolean
137 pjm2 1.1 Dim responseNumber As Integer
138    
139    
140     Private Sub Command1_Click()
141    
142 pjm2 1.5 ' build the contents of the XML packet.
143 pjm2 1.4 xml = "<packet></packet>"
144    
145 pjm2 1.2 ' Use the first winsock control to send a UDP packet.
146 pjm2 1.5 UDPSock.RemoteHost = filterHostname
147     UDPSock.RemotePort = filterUDPPort
148     UDPSock.SendData xml
149 pjm2 1.6 Status.Caption = "i-scream Winhost " & protocolVersion & " - UDP packet sent."
150 pjm2 1.1
151     End Sub
152    
153    
154     Private Sub Command3_Click()
155 pjm2 1.3 ' establish a TCP connection to a filter
156 pjm2 1.5 TCPSock.Close
157     TCPSock.Connect filterHostname, filterTCPPort
158 pjm2 1.1 End Sub
159    
160 pjm2 1.2 Private Sub Form_Load()
161     protocolVersion = "1.1"
162 pjm2 1.10
163     Status.Caption = "Loading"
164     Form1.Caption = "i-scream Winhost " & protocolVersion
165 pjm2 1.6
166 pjm2 1.4 ''''TEMP
167     filterManagerHostname = "killigrew.ukc.ac.uk"
168     filterManagerTCPPort = 4567
169 pjm2 1.10 Reconfigure_Click
170 pjm2 1.4 Exit Sub
171     ''' ENDTEMP
172    
173     On Error GoTo iniError
174     Dim buf As String * 256
175     Dim length As Long
176     length = GetPrivateProfileString("i-scream Winhost", "FilterManager", "<no value>", buf, Len(buf), App.Path & "winhost.ini")
177     filterManagerHostname = Left$(buf, length)
178     length = GetPrivateProfileString("i-scream Winhost", "FilterManagerPort", "<no value>", buf, Len(buf), App.Path & "winhost.ini")
179     filterManagerTCPPort = Left$(buf, length)
180    
181 pjm2 1.10 Status.Caption = "Connecting to Filter Manager"
182 pjm2 1.6
183 pjm2 1.4 Exit Sub
184    
185     iniError:
186     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")
187     End
188    
189     End Sub
190    
191 pjm2 1.10 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
192 pjm2 1.11 x = MsgBox("Are you sure you want to shut down the Winhost? This will stop your computer sending information to the i-scream Central Monitoring System.", vbYesNo, "i-scream Winhost")
193 pjm2 1.10 If x = 7 Then
194     Cancel = True
195     End If
196    
197     End Sub
198    
199 pjm2 1.11 Private Sub Hide_Click()
200     Form1.Visible = False
201     SystemTray.Icon = Val(Form1.Icon)
202     SystemTray.Action = 0
203     End Sub
204    
205 pjm2 1.10 Private Sub Reconfigure_Click()
206     ' establish a TCP connection to a filtermanager
207     connected = False
208     TCPSock.Close
209     TCPSock.Connect filterManagerHostname, filterManagerTCPPort
210 pjm2 1.11 End Sub
211    
212    
213    
214     Private Sub SystemTray_MouseDblClk(ByVal Button As Integer)
215    
216     Form1.Visible = True
217     Form1.SetFocus
218    
219 pjm2 1.10 End Sub
220    
221 pjm2 1.5 Private Sub TCPSock_Connect()
222 pjm2 1.6
223     responseNumber = 0
224 pjm2 1.1
225 pjm2 1.3 ' Send something as soon as we connect to the server.
226     If connected = False Then
227     ' contact the FilterManager
228 pjm2 1.5 TCPSock.SendData "STARTCONFIG" & vbCrLf
229 pjm2 1.3 Else
230     ' Contact the Filter
231 pjm2 1.5 TCPSock.SendData "HEARTBEAT" & vbCrLf
232 pjm2 1.3 End If
233 pjm2 1.1
234     End Sub
235    
236 pjm2 1.5 Private Sub TCPSock_DataArrival(ByVal bytesTotal As Long)
237 pjm2 1.1
238     responseNumber = responseNumber + 1
239    
240     ' Get the line from the server.
241 pjm2 1.5 TCPSock.GetData response, vbString, bytesTotal
242 pjm2 1.1
243     ' Remove linefeeds and returns from the line.
244     response = Replace(response, Chr(13), "")
245     response = Replace(response, Chr(10), "")
246     Text4.Text = Text4.Text & vbCrLf & response
247    
248 pjm2 1.2 If connected = False Then
249     ' Perform TCP configuration (1.1)
250     On Error GoTo configError
251     Select Case responseNumber
252     Case 1:
253     If Not response = "OK" Then GoTo configError
254 pjm2 1.5 TCPSock.SendData "LASTMODIFIED" & vbCrLf
255 pjm2 1.2 Case 2:
256     If response = "ERROR" Then GoTo configError
257 pjm2 1.3 lastModified = response
258 pjm2 1.5 TCPSock.SendData "FILELIST" & vbCrLf
259 pjm2 1.2 Case 3:
260     If response = "ERROR" Then GoTo configError
261 pjm2 1.3 fileList = response
262 pjm2 1.5 TCPSock.SendData "UDPUpdateTime" & vbCrLf
263 pjm2 1.2 Case 4:
264     If response = "ERROR" Then GoTo configError
265 pjm2 1.7 UDPUpdateTime = response
266 pjm2 1.5 TCPSock.SendData "TCPUpdateTime" & vbCrLf
267 pjm2 1.2 Case 5:
268     If response = "ERROR" Then GoTo configError
269 pjm2 1.7 TCPUpdateTime = response
270 pjm2 1.5 TCPSock.SendData "ENDCONFIG" & vbCrLf
271 pjm2 1.2 Case 6:
272     If Not response = "OK" Then GoTo configError
273 pjm2 1.5 TCPSock.SendData "FILTER" & vbCrLf
274 pjm2 1.2 Case 7:
275     'we got a filter list here.
276     readTo = 0
277     ' get hostname
278     readTo = InStr(1, response, ";", vbBinaryCompare)
279     filterHostname = Mid(response, 1, readTo - 1)
280     response = Mid(response, readTo + 1, Len(response))
281     ' get UDP Port number
282     readTo = InStr(1, response, ";")
283     filterUDPPort = Mid(response, 1, readTo - 1)
284     response = Mid(response, readTo + 1, Len(response))
285     ' get TCP Port number
286     filterTCPPort = response
287 pjm2 1.5 TCPSock.SendData "END" & vbCrLf
288 pjm2 1.2 Case 8:
289     If Not response = "OK" Then GoTo configError
290     connected = True
291     responseNumber = 0
292 pjm2 1.5 TCPSock.Close
293 pjm2 1.2 Text4.Text = Text4.Text & vbCrLf & " <closed>"
294 pjm2 1.10 Status.Caption = "Configuration successful"
295 pjm2 1.8 Label3.Caption = UDPUpdateTime
296     Label4.Caption = TCPUpdateTime
297     Timer1.Interval = 1000
298 pjm2 1.2 End Select
299     Else
300     ' Perform a heartbeat (1.1)
301     On Error GoTo heartbeatError
302     Select Case responseNumber
303     Case 1:
304 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
305 pjm2 1.5 TCPSock.SendData "CONFIG" & vbCrLf
306 pjm2 1.2 Case 2:
307 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
308 pjm2 1.5 TCPSock.SendData fileList & vbCrLf
309 pjm2 1.2 Case 3:
310 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
311 pjm2 1.5 TCPSock.SendData lastModified & vbCrLf
312 pjm2 1.2 Case 4:
313 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
314 pjm2 1.5 TCPSock.SendData "ENDHEARTBEAT" & vbCrLf
315 pjm2 1.2 Case 5:
316 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
317 pjm2 1.5 TCPSock.Close
318 pjm2 1.10 Status.Caption = "Heartbeat sent successfully."
319 pjm2 1.2 End Select
320    
321     End If
322    
323    
324     Exit Sub
325    
326     configError:
327 pjm2 1.10 Status.Caption = "FAILED to get configuration"
328 pjm2 1.8 Exit Sub
329 pjm2 1.2 heartbeatError:
330 pjm2 1.10 Status.Caption = "Heatbeat FAILED"
331 pjm2 1.8 Exit Sub
332 pjm2 1.1 End Sub
333 pjm2 1.5
334 pjm2 1.8 Private Sub Timer1_Timer()
335    
336     Label3.Caption = Label3.Caption - 1
337     Label4.Caption = Label4.Caption - 1
338    
339 pjm2 1.10 Status.Caption = ""
340 pjm2 1.8
341     If Label3.Caption < 1 Then
342     ' build the contents of the XML packet.
343     xml = "<packet></packet>"
344    
345     ' Use the first winsock control to send a UDP packet.
346     UDPSock.RemoteHost = filterHostname
347     UDPSock.RemotePort = filterUDPPort
348     UDPSock.SendData xml
349 pjm2 1.10 Status.Caption = "UDP packet sent"
350 pjm2 1.8 Label3.Caption = UDPUpdateTime
351     End If
352    
353     If Label4.Caption < 1 Then
354     ' establish a TCP connection to a filter
355     TCPSock.Close
356     TCPSock.Connect filterHostname, filterTCPPort
357     Label4.Caption = TCPUpdateTime
358     End If
359    
360     End Sub