本帖最后由 tubaba 于 2017-8-17 15:12 编辑
存在一个数据类型转换问题,定义收到04即接收完成
Func _TCPRecv()
Local $recv, $string = ''
While 1
$recv = TCPRecv($ConnectedSocket, 9, 1)
If ($recv = '' And (Not @error)) Or @error Then ExitLoop
If $recv <> '' Then
$string &= StringRegExpReplace($recv, '(?:0x)(.+)', '$1')
If StringRight($string, 2) == '04' Then ExitLoop
EndIf
WEnd
;~ $string= BinaryToString('0x' & $string, 4)
If StringRight($string, 2) == '04' Then
$string = BinaryToString('0x' & StringTrimRight($string, 2), 4)
Else
$string = BinaryToString('0x' & $string, 4)
EndIf
If $string = '' Then Return SetError(1, 0, $string)
;~ FileWrite('out1.txt',$string)
Return SetError(0, 0, $string)
EndFunc ;==>_TCPRecv
|