VB中Wimsock利用UDP协议传送大文件,总是重复接收!
发送端的代码:
Private Sub cmdSendFile_Click()
Dim size() As Byte '定义一个字节数组
Dim m As Integer
Dim filenum1 As String
Dim i As Integer
ReDim size(1024) '重定义它的大小是1024字节,即每次发送1K
filenum1 = FreeFile
Open App.Path & "\1111.txt" For Binary As filenum1
m = 1
For i = 1 To LOF(filenum1) \ 1024
Get filenum1, m, size
m = 1024 * i
udpPeerA.SendData size
Next
If LOF(filenum1) > (LOF(filenum1) \ 1024) * 1000 Then
ReDim size(LOF(filenum1) - (LOF(filenum1) \ 1024) * 1024) '重定义大小,将剩余部分发送
Get filenum1, m, size
udpPeerA.SendData size
End If
Close
MsgBox "发送完成!"
End Sub
接收端的代码:
Private Sub udpPeerB_DataArrival(ByVal bytesTotal As Long)
Dim bytData() As Byte
Dim lLenFile As Long
Dim myPath As String
Dim f
f = FreeFile
myPath = VB.App.Path & "\NewFile.txt"
Open myPath For Binary As #f 'myPath是文件名
lLenFile = LOF(f)
ReDim bytData(1 To bytesTotal)
udpPeerB.GetData bytData
If lLenFile = 0 Then
Put #f, 1, bytData
Else
Put #f, lLenFile + 1, bytData
End If
Close #f
End Sub]
运行的结果是接收端总是重复接收分段发送的那第一段的数据,(因为发送端是用数组把大文件分成若干段后每次发送一段的),而除了发送的第一段的内容被重复接收外,文件剩余的其他段接收端都收不到,收到的只是第一段的数据的重复.
不知道为什么,请高手指点一下阿,感谢不尽!!!
求求啦!!!!!
[此贴子已经被作者于2006-12-27 10:03:12编辑过]