40 If cmdBeginListen.caption <> "Server Listening..." Then
50 Set tcpServer = New MSWinsockLib.winsock
60 tcpServer.Protocol = sckTCPProtocol ' sckUDPProtocol
70 tcpServer.LocalPort = Me.txtPorta
80 tcpServer.Listen
90 cmdBeginListen.caption = "Server Listening..."
100 cmdBeginListen.backColor = COLOR.COLOR_IS_green
110 Me.caption = "Main - <IP>" & tcpServer.LocalIP & ":<Port>" & tcpServer.LocalPort
120 Me.txtMESSAGGI = Prefisso_Log() & "BeginListen - Connected - Main - <IP>" & tcpServer.LocalIP & ":<Port>" & tcpServer.LocalPort & Chr(13) & Chr(10) & Me.txtMESSAGGI
130 Me.txtIpAddress.Enabled = False
140 Me.txtPorta.Enabled = False
150 Else
160 tcpServer.Close
170 Set tcpServer = Nothing
180 cmdBeginListen.caption = "Begin Listen"
190 cmdBeginListen.backColor = COLOR.COLOR_IS_red
200 Me.cmdConnesso.caption = "NON COSNESSO"
210 cmdConnesso.backColor = COLOR.COLOR_IS_red
220 Me.caption = "Main"
230 Me.txtMESSAGGI = Prefisso_Log() & "BeginListen - DisConnected" & Chr(13) & Chr(10) & Me.txtMESSAGGI
240 Me.txtIpAddress.Enabled = True
250 Me.txtPorta.Enabled = True
260 End If
Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)
10 On Error GoTo eh_tcpServer_ConnectionRequest
Dim Tempo_Ingresso_Routine As Single, Tempo_uscita_Routine As Single
20 Tempo_Ingresso_Routine = timer2()
30 Debug.Print "Form_frmVerificaSocketServer-tcpServer_ConnectionRequest", "Timer Ingresso = " & Format$(Tempo_Ingresso_Routine, "00000.000")
40 If tcpServer.State <> sckClosed Then tcpServer.Close
50 tcpServer.Accept requestID
60 cmdConnesso.caption = "CLIENT CONNESSO"
70 cmdConnesso.backColor = COLOR.COLOR_IS_green
90 Me.txtMESSAGGI = Prefisso_Log() & "ConnectionRequest - Richiesta connessione da ID = " & requestID & " - Remote Host = " & tcpServer.RemoteHost & "/" & tcpServer.RemoteHostIP & "/" & tcpServer.RemotePort & Chr(13) & Chr(10) & Me.txtMESSAGGI
100 Debug.Print "Richiesta connessione da ID = " & requestID
110 Exit Sub
120 Tempo_uscita_Routine = timer2()
130 Debug.Print "Form_frmVerificaSocketServer-tcpServer_ConnectionRequest", "Timer Uscita = " & Format$(Tempo_uscita_Routine, "00000.000") & " Tempo Impiegato = " & Tempo_uscita_Routine - Format$(Tempo_Ingresso_Routine, "00000.000")
140 Debug.Print "----------------------------------------------------------------------------------"
150 Exit Sub
eh_tcpServer_ConnectionRequest:
160 msg_err err.Number, Erl, Error, "tcpServer_ConnectionRequest of Documento VBA Form_frmVerificaSocketServer"
170 Resume Next
End Sub
Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)
10 On Error GoTo eh_tcpServer_DataArrival
Dim Tempo_Ingresso_Routine As Single, Tempo_uscita_Routine As Single
20 Tempo_Ingresso_Routine = timer2()
30 Debug.Print "Form_frmVerificaSocketServer-tcpServer_DataArrival", "Timer Ingresso = " & Format$(Tempo_Ingresso_Routine, "00000.000")
Dim DATA As String
40 tcpServer.GetData DATA
50 Me.txtMESSAGGI = Prefisso_Log() & "DataArrival - " & DATA & Chr(13) & Chr(10) & Me.txtMESSAGGI
60 Tempo_uscita_Routine = timer2()
70 Debug.Print "Form_frmVerificaSocketServer-tcpServer_DataArrival", "Timer Uscita = " & Format$(Tempo_uscita_Routine, "00000.000") & " Tempo Impiegato = " & Tempo_uscita_Routine - Format$(Tempo_Ingresso_Routine, "00000.000")
80 Debug.Print "----------------------------------------------------------------------------------"
90 Exit Sub
eh_tcpServer_DataArrival:
100 msg_err err.Number, Erl, Error, "tcpServer_DataArrival of Documento VBA Form_frmVerificaSocketServer"
110 Resume Next
End Sub
Private Sub tcpServer_Close()
10 On Error GoTo eh_tcpServer_Close
Dim Tempo_Ingresso_Routine As Single, Tempo_uscita_Routine As Single
20 Tempo_Ingresso_Routine = timer2()
30 Debug.Print "Form_frmVerificaSocketServer-tcpServer_Close", "Timer Ingresso = " & Format$(Tempo_Ingresso_Routine, "00000.000")
40 cmdConnesso.caption = "NON CONNESSO"
50 cmdConnesso.backColor = COLOR.COLOR_IS_red
' Chiusura connessione...
60 tcpServer.Close
70 Set tcpServer = Nothing
80 cmdBeginListen.caption = "NON CONNESSO"
90 cmdBeginListen.backColor = COLOR.COLOR_IS_red
' ... e successiva riapertura
100 Set tcpServer = New MSWinsockLib.winsock
110 tcpServer.LocalPort = Me.txtPorta
120 tcpServer.Listen
130 cmdBeginListen.caption = "Server Listening..."
140 cmdBeginListen.backColor = COLOR.COLOR_IS_green
150 Me.caption = "Main - <IP>" & tcpServer.LocalIP & ":<Port>" & tcpServer.LocalPort
160 Me.txtMESSAGGI = Prefisso_Log() & "tcpServer_Close - Client Disconnected - Main - <IP>" & tcpServer.LocalIP & ":<Port>" & tcpServer.LocalPort & Chr(13) & Chr(10) & Me.txtMESSAGGI
170 Tempo_uscita_Routine = timer2()
180 Debug.Print "Form_frmVerificaSocketServer-tcpServer_Close", "Timer Uscita = " & Format$(Tempo_uscita_Routine, "00000.000") & " Tempo Impiegato = " & Tempo_uscita_Routine - Format$(Tempo_Ingresso_Routine, "00000.000")
190 Debug.Print "----------------------------------------------------------------------------------"
200 Exit Sub
eh_tcpServer_Close:
210 msg_err err.Number, Erl, Error, "tcpServer_Close of Documento VBA Form_frmVerificaSocketServer"
220 Resume Next
End Sub
Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)
10 On Error GoTo eh_tcpServer_ConnectionRequest
Dim Tempo_Ingresso_Routine As Single, Tempo_uscita_Routine As Single
20 Tempo_Ingresso_Routine = timer2()
30 Debug.Print "Form_frmVerificaSocketServer-tcpServer_ConnectionRequest", "Timer Ingresso = " & Format$(Tempo_Ingresso_Routine, "00000.000")
40 If tcpServer.State <> sckClosed Then tcpServer.Close
50 tcpServer.Accept requestID
60 cmdConnesso.caption = "CLIENT CONNESSO"
70 cmdConnesso.backColor = COLOR.COLOR_IS_green
90 Me.txtMESSAGGI = Prefisso_Log() & "ConnectionRequest - Richiesta connessione da ID = " & requestID & " - Remote Host = " & tcpServer.RemoteHost & "/" & tcpServer.RemoteHostIP & "/" & tcpServer.RemotePort & Chr(13) & Chr(10) & Me.txtMESSAGGI
100 Debug.Print "Richiesta connessione da ID = " & requestID
110 Exit Sub
120 Tempo_uscita_Routine = timer2()
130 Debug.Print "Form_frmVerificaSocketServer-tcpServer_ConnectionRequest", "Timer Uscita = " & Format$(Tempo_uscita_Routine, "00000.000") & " Tempo Impiegato = " & Tempo_uscita_Routine - Format$(Tempo_Ingresso_Routine, "00000.000")
140 Debug.Print "----------------------------------------------------------------------------------"
150 Exit Sub
eh_tcpServer_ConnectionRequest:
160 msg_err err.Number, Erl, Error, "tcpServer_ConnectionRequest of Documento VBA Form_frmVerificaSocketServer"
170 Resume Next
End Sub