ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/host/vb_net_test/nettest.frm
Revision: 1.6
Committed: Fri Feb 23 10:53:30 2001 UTC (23 years, 9 months ago) by pjm2
Branch: MAIN
Changes since 1.5: +26 -25 lines
Log Message:
A label on the form now keeps onlookers up to date with what's going on.

File Contents

# Content
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 = 3
22 Top = 2520
23 Width = 1575
24 End
25 Begin VB.TextBox Text4
26 Height = 1575
27 Left = 240
28 MultiLine = -1 'True
29 ScrollBars = 2 'Vertical
30 TabIndex = 2
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 = 1
40 Top = 2040
41 Width = 1935
42 End
43 Begin MSWinsockLib.Winsock TCPSock
44 Left = 4920
45 Top = 120
46 _ExtentX = 741
47 _ExtentY = 741
48 _Version = 393216
49 End
50 Begin VB.CommandButton Command1
51 Caption = "Send UDP"
52 Height = 375
53 Left = 4320
54 TabIndex = 0
55 Top = 1560
56 Width = 975
57 End
58 Begin MSWinsockLib.Winsock UDPSock
59 Left = 4320
60 Top = 120
61 _ExtentX = 741
62 _ExtentY = 741
63 _Version = 393216
64 Protocol = 1
65 End
66 Begin VB.Label Status
67 Caption = "Status:"
68 Height = 255
69 Left = 120
70 TabIndex = 4
71 Top = 5280
72 Width = 5415
73 End
74 End
75 Attribute VB_Name = "Form1"
76 Attribute VB_GlobalNameSpace = False
77 Attribute VB_Creatable = False
78 Attribute VB_PredeclaredId = True
79 Attribute VB_Exposed = False
80 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
81 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
82
83 Dim filterManagerHostname As String
84 Dim filterManagerTCPPort As Integer
85
86 Dim filterHostname As String
87 Dim filterTCPPort As Integer
88 Dim filterUDPPort As Integer
89 Dim fileList As String
90 Dim lastModified As String
91
92 Dim protocolVersion As String
93 Dim connected As Boolean
94 Dim responseNumber As Integer
95
96
97 Private Sub Command1_Click()
98
99 ' build the contents of the XML packet.
100 xml = "<packet></packet>"
101
102 ' Use the first winsock control to send a UDP packet.
103 UDPSock.RemoteHost = filterHostname
104 UDPSock.RemotePort = filterUDPPort
105 UDPSock.SendData xml
106 Status.Caption = "i-scream Winhost " & protocolVersion & " - UDP packet sent."
107
108 End Sub
109
110 Private Sub Command2_Click()
111
112 ' establish a TCP connection to a filtermanager
113 TCPSock.Close
114 TCPSock.Connect filterManagerHostname, filterManagerTCPPort
115
116 End Sub
117
118 Private Sub Command3_Click()
119 ' establish a TCP connection to a filter
120 TCPSock.Close
121 TCPSock.Connect filterHostname, filterTCPPort
122 End Sub
123
124 Private Sub Form_Load()
125 protocolVersion = "1.1"
126
127 Status.Caption = "i-scream Winhost " & protocolVersion
128
129 ''''TEMP
130 filterManagerHostname = "killigrew.ukc.ac.uk"
131 filterManagerTCPPort = 4567
132 Exit Sub
133 ''' ENDTEMP
134
135 On Error GoTo iniError
136 Dim buf As String * 256
137 Dim length As Long
138 length = GetPrivateProfileString("i-scream Winhost", "FilterManager", "<no value>", buf, Len(buf), App.Path & "winhost.ini")
139 filterManagerHostname = Left$(buf, length)
140 length = GetPrivateProfileString("i-scream Winhost", "FilterManagerPort", "<no value>", buf, Len(buf), App.Path & "winhost.ini")
141 filterManagerTCPPort = Left$(buf, length)
142
143 Status.Caption = "i-scream Winhost " & protocolVersion & " connecting to Filter Manager"
144
145 Exit Sub
146
147 iniError:
148 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")
149 End
150
151 End Sub
152
153 Private Sub Label1_Click()
154
155 End Sub
156
157 Private Sub TCPSock_Connect()
158
159 responseNumber = 0
160
161 ' Send something as soon as we connect to the server.
162 If connected = False Then
163 ' contact the FilterManager
164 TCPSock.SendData "STARTCONFIG" & vbCrLf
165 Else
166 ' Contact the Filter
167 TCPSock.SendData "HEARTBEAT" & vbCrLf
168 End If
169
170 End Sub
171
172 Private Sub TCPSock_DataArrival(ByVal bytesTotal As Long)
173
174 responseNumber = responseNumber + 1
175
176 ' Get the line from the server.
177 TCPSock.GetData response, vbString, bytesTotal
178
179 ' Remove linefeeds and returns from the line.
180 response = Replace(response, Chr(13), "")
181 response = Replace(response, Chr(10), "")
182 Text4.Text = Text4.Text & vbCrLf & response
183
184 If connected = False Then
185 ' Perform TCP configuration (1.1)
186 On Error GoTo configError
187 Select Case responseNumber
188 Case 1:
189 If Not response = "OK" Then GoTo configError
190 TCPSock.SendData "LASTMODIFIED" & vbCrLf
191 Case 2:
192 If response = "ERROR" Then GoTo configError
193 lastModified = response
194 TCPSock.SendData "FILELIST" & vbCrLf
195 Case 3:
196 If response = "ERROR" Then GoTo configError
197 fileList = response
198 TCPSock.SendData "UDPUpdateTime" & vbCrLf
199 Case 4:
200 If response = "ERROR" Then GoTo configError
201 TCPSock.SendData "TCPUpdateTime" & vbCrLf
202 Case 5:
203 If response = "ERROR" Then GoTo configError
204 TCPSock.SendData "ENDCONFIG" & vbCrLf
205 Case 6:
206 If Not response = "OK" Then GoTo configError
207 TCPSock.SendData "FILTER" & vbCrLf
208 Case 7:
209 'we got a filter list here.
210 readTo = 0
211 ' get hostname
212 readTo = InStr(1, response, ";", vbBinaryCompare)
213 filterHostname = Mid(response, 1, readTo - 1)
214 response = Mid(response, readTo + 1, Len(response))
215 ' get UDP Port number
216 readTo = InStr(1, response, ";")
217 filterUDPPort = Mid(response, 1, readTo - 1)
218 response = Mid(response, readTo + 1, Len(response))
219 ' get TCP Port number
220 filterTCPPort = response
221 TCPSock.SendData "END" & vbCrLf
222 Case 8:
223 If Not response = "OK" Then GoTo configError
224 connected = True
225 responseNumber = 0
226 TCPSock.Close
227 Text4.Text = Text4.Text & vbCrLf & " <closed>"
228 Status.Caption = "i-scream Winhost " & protocolVersion & " - got config okay"
229 End Select
230 Else
231 ' Perform a heartbeat (1.1)
232 On Error GoTo heartbeatError
233 Select Case responseNumber
234 Case 1:
235 If Not response = "OK" Then GoTo heartbeatError
236 TCPSock.SendData "CONFIG" & vbCrLf
237 Case 2:
238 If Not response = "OK" Then GoTo heartbeatError
239 TCPSock.SendData fileList & vbCrLf
240 Case 3:
241 If Not response = "OK" Then GoTo heartbeatError
242 TCPSock.SendData lastModified & vbCrLf
243 Case 4:
244 If Not response = "OK" Then GoTo heartbeatError
245 TCPSock.SendData "ENDHEARTBEAT" & vbCrLf
246 Case 5:
247 If Not response = "OK" Then GoTo heartbeatError
248 TCPSock.Close
249 Status.Caption = "i-scream Winhost " & protocolVersion & " - heartbeat sent okay."
250 End Select
251
252 End If
253
254
255 Exit Sub
256
257 configError:
258 Status.Caption = "i-scream Winhost " & protocolVersion & " - FAILED to get configuration"
259 heartbeatError:
260 Status.Caption = "i-scream Winhost " & protocolVersion & " - Heatbeat FAILED"
261 End Sub
262