用 TCP 建立了 SERVER 第一次连接一切正常。可是,如果 CLIENT 断开后,再次连接就连不上了。如果等5分钟就又可以了。Private Sub tcpServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
intMax = intMax + 1
Load tcpServer(intMax)
tcpServer(intMax).LocalPort = 0
tcpServer(intMax).Accept requestID
Load txtData(intMax)
ConnectUDP (intMax)
End If
End SubPrivate Sub ConnectUDP(tcpServerIndex As String)
If tcpServer(tcpServerIndex).State = sckConnected Then
Dim strData As String
lblLog.Caption = lblLog.Caption & tcpServer(tcpServerIndex).RemoteHostIP _
& " connected at " & Date & " " & Time & vbNewLine
strData = CStr(5000 + intUDP)
tcpServer(tcpServerIndex).SendData strData
If intUDP > 0 Then
Load udpServer(intUDP)
End If
With udpServer(intUDP)
.RemoteHost = tcpServer(tcpServerIndex).RemoteHostIP
.RemotePort = 5300
.LocalPort = 5000 + intUDP
.Bind (5000 + intUDP)
End With
intUDP = intUDP + 1
End If
End Sub
If Index = 0 Then
intMax = intMax + 1
Load tcpServer(intMax)
tcpServer(intMax).LocalPort = 0
tcpServer(intMax).Accept requestID
Load txtData(intMax)
ConnectUDP (intMax)
End If
End SubPrivate Sub ConnectUDP(tcpServerIndex As String)
If tcpServer(tcpServerIndex).State = sckConnected Then
Dim strData As String
lblLog.Caption = lblLog.Caption & tcpServer(tcpServerIndex).RemoteHostIP _
& " connected at " & Date & " " & Time & vbNewLine
strData = CStr(5000 + intUDP)
tcpServer(tcpServerIndex).SendData strData
If intUDP > 0 Then
Load udpServer(intUDP)
End If
With udpServer(intUDP)
.RemoteHost = tcpServer(tcpServerIndex).RemoteHostIP
.RemotePort = 5300
.LocalPort = 5000 + intUDP
.Bind (5000 + intUDP)
End With
intUDP = intUDP + 1
End If
End Sub
With Me.sockServer
If .State <> sckClose Then .Close
.LocalPort = PORT
.Listen
End With