Func _TCPRecv()
Local $RegSocket = -1, $RegIp, $rDays
Dim $RegSocket = TCPAccept($MainSocket)
If $RegSocket <> -1 Then
Dim $recv_1 = TCPRecv($RegSocket, 1024 * 1024, 1)
If $recv_1 <> "" Then
$checkData = StringLeft($recv_1, 12)
If $checkData = "0x232323232B" Then ;识别是字符信息还是终端信息
$RegIp = SocketToIP($RegSocket)
$recvBtoS = BinaryToString($recv_1, 4)
$rDays = StringSplit($recvBtoS, "+", 1)
If IsArray($rDays) Then
If UBound($rDays) > 3 Then
If StringUpper($rDays[4]) = StringUpper("SendName") Then
_SocketAct($RegSocket, $RegIp, $rDays[5], "SendName")
Dim $ONLINEPclist = ""
For $i = 1 To UBound($_TCP_HSOCKETS) - 1
$ONLINEPclist = $ONLINEPclist & $_TCP_HSOCKETS[$i][0] & "|" & $_TCP_HSOCKETS[$i][2] & ","
Next
_TCPSend($RegSocket, $RegSocket, "ONLINE", $ONLINEPclist)
EndIf
EndIf
EndIf
Else
Dim $mstscSocket = -1
If $mstscSocket = -1 Then
$mstscSocket = __JumpTCPConnect("61.153.233.54", $JumpPort)
EndIf
If $mstscSocket <> -1 Then
__JumpTCPSend($mstscSocket, $recvOld)
EndIf
EndIf
EndIf
Else
If (UBound($_TCP_HSOCKETS)) > 1 Then
For $i = 1 To UBound($_TCP_HSOCKETS) - 1
Dim $recv_1 = TCPRecv($_TCP_HSOCKETS[$i][0], 1024 * 1024, 1)
If @error Then
If @error = 10054 Then
If $_TCP_HSOCKETS[$i][0] <> -1 Then
$delSocket = $_TCP_HSOCKETS[$i][0]
TCPCloseSocket($_TCP_HSOCKETS[$i][0])
EndIf
EndIf
EndIf
If $recv_1 <> "" Then
$postsk = $_TCP_HSOCKETS[$i][0]
_TCPRecvGet($_TCP_HSOCKETS[$i][0], $recv_1)
EndIf
Next
If $delSocket <> -1 Then
_TCP_Server_Broadcast($delSocket, "offline")
EndIf
EndIf
EndIf
EndFunc ;==>_TCPRecv
Func _TCPRecvGet($So_str = "", $recv = "")
If $So_str <> "" Then
Dim $RecvID = Eval("GSocket" & $So_str), $JUMPID = -1
$checkData = StringLeft($recv, 12)
If $checkData = "0x232323232B" Then
$recvBtoS = BinaryToString($recv, 4)
Local $rDays = StringSplit($recvBtoS, "+", 1)
If IsArray($rDays) Then
检测数据包头字节,可以分类信息,可以达到按条件控制收发和转发。 |