'接收
Private Sub wskS_DataArrival(Index As Integer, ByVal bytesTotal As Long)
'On Error GoTo err1
    '接收文件
    Static i As Long
    Dim inFile() As Byte
    Dim myLong As Double
    Dim myPath As String
    Dim myFree As Long
    
    myPath = VB.App.Path & "\temp\abc.flv"
    
    ReDim inFile(bytesTotal)
    
    wskS(Index).GetData inFile, vbArray + vbByte
    myFree = FreeFile
    Open myPath For Binary As #myFree '新建文件
    Put #myFree, lenth + 1, inFile                  '将收到的数据写入新文件中
    Close #myFree                                   '关闭
    '记录文件长度
    lenth = lenth + UBound(inFile) - LBound(inFile) + 1
    
End Sub'发送
Public Function outFiles(filePath As String)
    Dim outPath As String
    Dim outFileLen As Double
    Dim outFileLenN As Double
    Dim outFileStar As Double
    Dim lngN As Double
    Dim outN As Double
    Dim outFree As Long
    Dim i As Long
    
    '检查是否与服务器连接
    outPath = VB.App.Path & "\temp\1.flv"    outFileLen = FileLen(outPath)
    outN = outFileLen \ 7000 + 1
    outFileLenN = outFileLen - (outN - 1) * 7000
    
    objJD.Max = outN
    dblJD = 0
    objJD.Value = 0
    If outFileStar = 0 Then outFileStar = 1
    If wskC.State = 7 Then
        For i = 0 To outN - 1
            If i = outN - 1 Then
                outFileStar = i * 7000 + 1
                lngN = outFileLen - outFileStar
            Else
                outFileStar = i * 7000 + 1
                lngN = 7000
            End If
            
            ReDim outFile(lngN)
            outFree = FreeFile
            Open outPath For Binary As #outFree
            Get #outFree, outFileStar, outFile
            Close #outFree
            
            wskC.SendData outFile
            
            DoEvents
            objJD.Value = i
            DoEvents
        Next
    End If
        
End Function

解决方案 »

  1.   

    在发送端
    是想把大文件拆开发送
    用这段代码做了文件的拆分组合测试
    通过
    Private Sub Command2_Click()
        Dim inPath As String
        Dim outPath As String
        Dim inFileLen As Double
        Dim outFileLen As Double
        Dim inFileStar As Double
        Dim outFileStar As Double
        Dim lngN As Double
        Dim outN As Double
        Dim inFree As Long
        Dim outFree As Long
        Dim i As Long
            '检查是否与服务器连接
        outPath = VB.App.Path & "\temp\1.flv"
        inPath = VB.App.Path & "\temp\2.flv"
        
        outFileLen = FileLen(outPath)
        outN = outFileLen \ 7000 + 1
        
        For i = 0 To outN - 1
        objJD.Max = outN
            objJD.Value = i
            If i = outN - 1 Then
                outFileStar = i * 7000 + 1
                lngN = outFileLen - outFileStar
            Else
                outFileStar = i * 7000 + 1
                lngN = 7000
            End If
            inFileStar = outFileStar
            
            ReDim outFile(lngN)
            outFree = FreeFile
            Open outPath For Binary As #outFree
            Get #outFree, outFileStar, outFile
            Close #outFree
            
            ReDim inFile(lngN)
            inFree = FreeFile
            Open inPath For Binary As #inFree        Put #inFree, inFileStar, outFile
            Close #inFree
            
            Open inPath For Binary As #inFree
            Get #inFree, inFileStar, inFile
            Close #inFree
            DoEvents
        Next
        
    End Sub