xg911335 发表于 2012-10-5 17:54:09

【已解决】TCP_UDF是不是有问题啊,传输的文件只能接收到一次信息(详进)

本帖最后由 xg911335 于 2012-10-6 03:11 编辑

服务器:
Func Receive($iError, $sreceive)
        $sString = StringSplit($sreceive,"|")
        If $sString = "Online" Then
                GUICtrlCreateListViewItem($sreceive&"|"&@YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC,$ListView1)
        ElseIf $sString = "Csend" Then
                $tmpFSize = $sString
                $tmpFName = $sString
                MsgBox(0,"服务器信息","客户端载屏文件名:"&$tmpFName&" 文件大小:"&$tmpFSize&"完成,准备上传……")
                $file = FileOpen(@ScriptDir & "\temp\"& $tmpFName &"",2+8+16)
                _TCP_Server_Send("Srecv|File")
        ElseIf $sString = "tfile" Then
                        FileWrite(@ScriptDir & "\temp\"& $tmpFName &"",BinaryToString($sString,4))
                        MsgBox(0,"S2",$sString)
        ElseIf $sreceive = "FileOver" Then
                        FileClose($file)
                                                ……………………       
                 ElseIf $sString = "Ctest" Then
                MsgBox(0,"S3",$sString)
        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,客户端收到后,也是偶尔一次不断循环向服务器发送信息?请问这是怎么回事?

republican 发表于 2012-10-5 22:24:36

代码逻辑有问题,UDF没问题。

xg911335 发表于 2012-10-6 03:11:28

已经搞定。谢谢楼上!

zhuang513 发表于 2013-3-8 18:54:34

学习看看..

shuaiw 发表于 2013-4-1 11:39:20

解决代码能发出来大家看看嘛?
我遇到一个问题是,传输文件,接收端只接收到文件,没有接收到文件里的内容,能给解决下吗?
页: [1]
查看完整版本: 【已解决】TCP_UDF是不是有问题啊,传输的文件只能接收到一次信息(详进)