我有
server端   client端两个程序工作原理是
SERVER发给CLIENT一个指令   CLIENT就发给SERVER一个文件包比如 #1 是请求第一个文件包   #2是第二个..结果,时常server端就收成了  #15#16等等...连起来了.. 怎么办?

解决方案 »

  1.   

    不要用循环连续发包
    最好在事件中处理完1个来回后 SERVER端再发送第二个请求 依次类推
      

  2.   

    楼上小刀,我就是那样的。
    CLIENT发#1 SERVER就发
    CLIENT发#1`  SERVER再给发
      

  3.   

    客户接收到一个包后,返回server一个信息,表示已经收到,server再发送
    因为tcp协议是不份数据边界的,和udp不通,所以发送频率过快数据会连在一起
      

  4.   

    我就是按您说的做的.是这样的吴哥! 但还是会连在一起.你什么时候上MSN.??
      

  5.   

    我做了一下根踪 
    以下是同一操作.两次分别得出的结果....说明一下, 我从 client发来的包是 0080015#1 到 0080015#59  最后以 008002结束1
    -------------------------------
    0080015#1
    0080015#2
    0080015#3
    0080015#4
    0080015#5
    0080015#60080015#70080015#8
    0080015#9
    0080015#10
    0080015#11
    0080015#120080015#130080015#140080015#150080015#160080015#17
    0080015#18
    0080015#190080015#200080015#210080015#220080015#23
    0080015#24
    0080015#250080015#26
    0080015#27
    0080015#280080015#29
    0080015#30
    0080015#310080015#32
    0080015#330080015#34
    0080015#35
    0080015#360080015#370080015#38
    0080015#39
    0080015#400080015#410080015#420080015#43
    0080015#44
    0080015#45
    0080015#460080015#470080015#480080015#490080015#50
    0080015#51
    0080015#520080015#530080015#540080015#550080015#56
    0080015#57
    0080015#580080015#590080022
    --------------------------------------
    0080015#1
    0080015#2
    0080015#30080015#4
    0080015#5
    0080015#60080015#70080015#80080015#90080015#10
    0080015#110080015#12
    0080015#130080015#140080015#150080015#16
    0080015#17
    0080015#180080015#190080015#200080015#210080015#22
    0080015#23
    0080015#240080015#250080015#260080015#270080015#28
    0080015#29
    0080015#300080015#310080015#320080015#33
    0080015#34
    0080015#350080015#360080015#370080015#380080015#39
    0080015#40
    0080015#410080015#420080015#430080015#440080015#45
    0080015#46
    0080015#470080015#480080015#490080015#500080015#51
    0080015#52
    0080015#530080015#540080015#550080015#560080015#57
    0080015#58
    0080015#59
      

  6.   

    如果你的Server和Client是一问一答的方式运作的话,是不会出现这种情况的。
    现在出现这种情况,说明它们并非工作在一问一答的方式下。估计你的Server是未逐一接收到Client地回答的情况下连续发送了若干个请求给Client。比如发送#1之后,在Client还未应答结束时又发了#2,甚至还有#3,……。
      

  7.   

    我也这么认为
    楼主你把server端 winsock1_dataarrive 事件中的代码发来看看
      

  8.   

    百分之一万的一问一答呀.... MSN [email protected]  有空麻烦加我,让你看代码
      

  9.   

    Private Sub wskUp_DataArrival(Index As Integer, ByVal bytesTotal As Long)
        Dim sTmp As String
        wskUp(Index).GetData sTmp
        Select Case Left(sTmp, 6)
            Case "008001"
                Dim sCmd() As String
                Dim lFile As Long
                Dim bytData() As Byte
                Dim lPos As Long
                Dim lFreeFile As Long
                Dim lPid As Long
                Dim cSub As Long            lPid = CLng(wskUp(Index).Tag)
                sCmd = Split(Right(sTmp, Len(sTmp) - 6), "#")
                lFile = CLng(pUpTransList(lPid).FileSize) '得到文件长度
                cSub = CLng(sCmd(1))
                           
                    lFreeFile = FreeFile
                    Open pResPath & "\" & pUpTransList(lPid).FileName For Binary As #lFreeFile      '打开文件
                
                     ReDim bytData(1 To PUB_LSUB)
                      Get #lFreeFile, lPos, bytData '把文件读入到数组里
                 wskUp(Index).SendData bytData
            Case "008002"
                  wskUp(Index).Close
        End Select
    End Sub
      

  10.   

    Private Sub wskDown_DataArrival(Index As Integer, ByVal bytesTotal As Long)
        Dim bytData() As Byte
        Dim lLenFile As Long
        Dim iFreeFile As Long
        Dim FileName As String
        Dim pInd As Long
        Dim lPos As Long
        Dim lBf As Long
       
        pInd = wskDown(Index).Tag
        iFreeFile = FreeFile
        FileName = TrimEx(pDownTransList(pInd).Path) & "\" & TrimEx(pDownTransList(pInd).FileName)
       
        Open FileName For Binary As #iFreeFile 'strFileName是文件名
        ReDim bytData(1 To bytesTotal)
        wskDown(Index).GetData bytData
       
        lPos = pTransPass(pInd, pDownTransList(pInd).Passage - 1)
        Put #iFreeFile, (lPos - 1) * PUB_LSUB + 1, bytData
        Close #iFreeFile
       
        Dim lLvFiles As Long
        lLvFiles = pDownTransList(pInd).ListIndex
        lBf = (PUB_LSUB * lPos) / pDownTransList(pInd).FileSize * 100
        If lBf > 100 Then lBf = 100
        If lBf < 1 Then
            lvFiles.ListItems(lLvFiles).SubItems(2) = "0%"
        Else
            lvFiles.ListItems(lLvFiles).SubItems(2) = FormatNumber(lBf, 0) & "%"
        End If
       
       
        pTransSub(pInd) = Left(pTransSub(pInd), lPos - 1) & Replace(pTransSub(pInd), "0", "1", lPos, 1)
        pTransPass(pInd, pDownTransList(pInd).Passage - 1) = lPos + 1
       
        If lPos < pDownTransList(pInd).cSub Then
            wskDown(Index).SendData "008001" & pDownTransList(pInd).FID & "#" & pTransPass(pInd, pDownTransList(pInd).Passage - 1)    '请求传输文件ID为1的第1块
            
        Else
            wskDown(Index).SendData "008002"    '完成
            wskDown(Index).Close
        End If
      

  11.   

    在senddata和getdata之后加doevents