本帖最后由 xg911335 于 2012-10-6 03:11 编辑
服务器:Func Receive($iError, $sreceive)
$sString = StringSplit($sreceive,"|")
If $sString[1] = "Online" Then
GUICtrlCreateListViewItem($sreceive&"|"&@YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC,$ListView1)
ElseIf $sString[1] = "Csend" Then
$tmpFSize = $sString[2]
$tmpFName = $sString[3]
MsgBox(0,"服务器信息","客户端载屏文件名:"&$tmpFName&" 文件大小:"&$tmpFSize&"完成,准备上传……")
$file = FileOpen(@ScriptDir & "\temp"& $tmpFName &"",2+8+16)
_TCP_Server_Send("Srecv|File")
ElseIf $sString[1] = "tfile" Then
FileWrite(@ScriptDir & "\temp"& $tmpFName &"",BinaryToString($sString[2],4))
MsgBox(0,"S2",$sString[2])
ElseIf $sreceive = "FileOver" Then
FileClose($file)
……………………
ElseIf $sString[1] = "Ctest" Then
MsgBox(0,"S3",$sString[2])
EndIf
EndFunc
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Case $zppic
_TCP_Server_Send("Image|Nmae|Size")
Case $clsj
_TCP_Server_Send("test")
EndSwitch
WEnd
客户端:While 1 ;循环接收服务器指令
Sleep(900)
$command=TCPRecv($ConnectedSocket,2048)
If @error Then
MsgBox(0,"Client","服务器与客户端断开")
ElseIf $command <> "" Then
_runcommand($command)
EndIf
WEnd ;循环接收服务器指令
Func _runcommand($str)
Switch $str
Case "Image|Nmae|Size"
$tmpNfile = @ComputerName &"_"& @YEAR & "" & @MON & "" & @MDAY & "_" & @HOUR & "" & @MIN & "" & @SEC & ".jpg"
$tmpimg = _ScreenCapture_Capture( @ScriptDir & "" & $tmpNfile)
Sleep(1000)
If $tmpimg = True Then
$tmpFsize = FileGetSize($tmpNfile)
$file = FileOpen($tmpNfile,16)
;$tmpOpen = FileOpen($tmpfile,16)
TCPSend($ConnectedSocket,"Csend|" & $tmpFsize &" | " & $tmpNfile & "")
Else
MsgBox(0,"客户端信息","载图失败.")
EndIf
Case "Srecv|File"
Do
$rDate = FileRead($file,1024 * 2)
If $rDate = 1 Then ExitLoop
$tmpDate = "tfile|"&$rDate&""
Sleep(500)
MsgBox(0,"C1",$tmpDate)
TCPSend($ConnectedSocket,$tmpDate)
If @error Then ;MsgBox(0,"C2","error")
Until $rDate = -1
MsgBox(0,"C3",$rDate)
$tmpFclose = FileClose($file)
TCPSend($ConnectedSocket,"FileOver")
Case "test"
While 1
Sleep(1000)
MsgBox(0,"C","Ctest|123123")
$tmptext = TCPSend($ConnectedSocket,"Ctest|123123")
If $tmptext = 0 Then MsgBox(0,"C","Error")
WEnd
EndSwitch
EndFunc
为什么偶尔有一次能接收文件,是不是这个TCP_UDF有问题啊?服务器发送一个test,客户端收到后,也是偶尔一次不断循环向服务器发送信息?请问这是怎么回事? |