--- projects/cms/source/host/winhost/nettest.frm 2001/02/22 17:04:22 1.1 +++ projects/cms/source/host/winhost/nettest.frm 2001/02/23 10:07:55 1.3 @@ -119,13 +119,20 @@ Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False +Dim filterHostname As String +Dim filterTCPPort As Integer +Dim filterUDPPort As Integer +Dim fileList As String +Dim lastModified As String + +Dim protocolVersion As String +Dim connected As Boolean Dim responseNumber As Integer Private Sub Command1_Click() - ' Use the first winsock control to send - ' a UDP packet. + ' Use the first winsock control to send a UDP packet. Winsock1.RemoteHost = Text3.Text Winsock1.RemotePort = Text2.Text Winsock1.SendData Text1.Text @@ -134,22 +141,34 @@ End Sub Private Sub Command2_Click() - ' establish a TCP connection to a machine + ' establish a TCP connection to a filtermanager Winsock2.Close Winsock2.Connect Text3.Text, Text2.Text End Sub Private Sub Command3_Click() - x = MsgBox("not implemented..") + ' establish a TCP connection to a filter + Winsock2.Close + Winsock2.Connect filterHostname, filterTCPPort End Sub +Private Sub Form_Load() + protocolVersion = "1.1" +End Sub + Private Sub Winsock2_Connect() responseNumber = 0 - ' As soon as we are connected to the server, send this. - Winsock2.SendData "STARTCONFIG" & vbCrLf + ' Send something as soon as we connect to the server. + If connected = False Then + ' contact the FilterManager + Winsock2.SendData "STARTCONFIG" & vbCrLf + Else + ' Contact the Filter + Winsock2.SendData "HEARTBEAT" & vbCrLf + End If End Sub @@ -165,25 +184,81 @@ Private Sub Winsock2_DataArrival(ByVal bytesTotal As L response = Replace(response, Chr(10), "") Text4.Text = Text4.Text & vbCrLf & response - ' Decide what to send back to the server. - Select Case responseNumber - Case 1: - Winsock2.SendData "LASTMODIFIED" & vbCrLf - Case 2: - Winsock2.SendData "FILELIST" & vbCrLf - Case 3: - Winsock2.SendData "UDPUpdateTime" & vbCrLf - Case 4: - Winsock2.SendData "TCPUpdateTime" & vbCrLf - Case 5: - Winsock2.SendData "ENDCONFIG" & vbCrLf - Case 6: - Winsock2.SendData "FILTER" & vbCrLf - Case 7: - Winsock2.SendData "END" & vbCrLf - Case 8: - Winsock2.Close - Text4.Text = Text4.Text & vbCrLf & " " - End Select + If connected = False Then + ' Perform TCP configuration (1.1) + On Error GoTo configError + Select Case responseNumber + Case 1: + If Not response = "OK" Then GoTo configError + Winsock2.SendData "LASTMODIFIED" & vbCrLf + Case 2: + If response = "ERROR" Then GoTo configError + lastModified = response + Winsock2.SendData "FILELIST" & vbCrLf + Case 3: + If response = "ERROR" Then GoTo configError + fileList = response + Winsock2.SendData "UDPUpdateTime" & vbCrLf + Case 4: + If response = "ERROR" Then GoTo configError + Winsock2.SendData "TCPUpdateTime" & vbCrLf + Case 5: + If response = "ERROR" Then GoTo configError + Winsock2.SendData "ENDCONFIG" & vbCrLf + Case 6: + If Not response = "OK" Then GoTo configError + Winsock2.SendData "FILTER" & vbCrLf + Case 7: + 'we got a filter list here. + readTo = 0 + ' get hostname + readTo = InStr(1, response, ";", vbBinaryCompare) + filterHostname = Mid(response, 1, readTo - 1) + response = Mid(response, readTo + 1, Len(response)) + ' get UDP Port number + readTo = InStr(1, response, ";") + filterUDPPort = Mid(response, 1, readTo - 1) + response = Mid(response, readTo + 1, Len(response)) + ' get TCP Port number + filterTCPPort = response + Winsock2.SendData "END" & vbCrLf + Case 8: + If Not response = "OK" Then GoTo configError + connected = True + responseNumber = 0 + Winsock2.Close + Text4.Text = Text4.Text & vbCrLf & " " + x = MsgBox("got config okay") + End Select + Else + ' Perform a heartbeat (1.1) + On Error GoTo heartbeatError + Select Case responseNumber + Case 1: + If Not response = "OK" Then GoTo heartbeatError + Winsock2.SendData "CONFIG" & vbCrLf + Case 2: + If Not response = "OK" Then GoTo heartbeatError + Winsock2.SendData fileList & vbCrLf + Case 3: + If Not response = "OK" Then GoTo heartbeatError + Winsock2.SendData lastModified & vbCrLf + Case 4: + If Not response = "OK" Then GoTo heartbeatError + Winsock2.SendData "ENDHEARTBEAT" & vbCrLf + Case 5: + If Not response = "OK" Then GoTo heartbeatError + Winsock2.Close + x = MsgBox("heartbeat sent okay.") + End Select + + End If + + + Exit Sub + +configError: + x = MsgBox("error doing configuration") +heartbeatError: End Sub