一个发送和接收文件的代码,可收到的文件总是不对,各位高手看看问题在哪儿?
'接收
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