vb6.0怎么用winsock发送大文件
像传输1G的电影,怎么弄?PrivateSubCommand2_Click()Dima()AsByteIfWinsock1.State=sckClosedThenMsgB...
像传输1G的电影,怎么弄?
Private Sub Command2_Click()
Dim a() As Byte
If Winsock1.State = sckClosed Then
MsgBox "错误", vbCritical, "Alert"
Exit Sub
End If
y = InputBox("请输入文件类型", "")
CommonDialog1.Filter = "*." & y
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then
Exit Sub
End If
send_filename = CommonDialog1.FileName
Open send_filename For Binary As #1
If LOF(1) <= 1012 Then
ReDim a(LOF(1) - 1) As Byte
Get #1, , a
Winsock1.SendData a
Close
Exit Sub
End If
If LOF(1) > 1012 Then
lump = LOF(1) \ 1012
left_lump = LOF(1) Mod 1012
For i = 1 To lump
ReDim a(1 To 1012) As Byte
Get #1, , a
Winsock1.SendData a
Next
Exit Sub
End If
If left_lump > 0 Then
ReDim a(1 To left_lump) As Byte
Get #1, , a
Winsock1.SendData a
End If
Close
Exit Sub
End Sub
这是我的发送端的代码,怎么改? 展开
Private Sub Command2_Click()
Dim a() As Byte
If Winsock1.State = sckClosed Then
MsgBox "错误", vbCritical, "Alert"
Exit Sub
End If
y = InputBox("请输入文件类型", "")
CommonDialog1.Filter = "*." & y
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then
Exit Sub
End If
send_filename = CommonDialog1.FileName
Open send_filename For Binary As #1
If LOF(1) <= 1012 Then
ReDim a(LOF(1) - 1) As Byte
Get #1, , a
Winsock1.SendData a
Close
Exit Sub
End If
If LOF(1) > 1012 Then
lump = LOF(1) \ 1012
left_lump = LOF(1) Mod 1012
For i = 1 To lump
ReDim a(1 To 1012) As Byte
Get #1, , a
Winsock1.SendData a
Next
Exit Sub
End If
If left_lump > 0 Then
ReDim a(1 To left_lump) As Byte
Get #1, , a
Winsock1.SendData a
End If
Close
Exit Sub
End Sub
这是我的发送端的代码,怎么改? 展开
2个回答
展开全部
这跟文件大小有什么关系。用内存映射技术读取大文件,用tcp协议的socket发送出去,多大的都没问题。要注意映射块的剩余量问题,不够一次发送量时要先暂存,读取下一映射块后再发送。这样实现可以达到局域网的最大带宽速度。如果偷懒使用win api,速度可能就几m而已。
追问
那怎么弄啊?能给个代码吗?谢谢
追答
没有vb的例子,只有c++的,贴出来也没用。你看看这个,也许合用,这种事vb不是强项:
http://wenku.baidu.com/view/3989521810a6f524ccbf8566.html
展开全部
'读一段发一段,直到结束,使用2进制读取文件,每读取一段发送成功后指针向后移动sendfilesize再读取,当然中间要加eof判断
Const sendfilesize = 1024 '发送文件块大小
Private Sub Command1_Click()
Dim a() As Byte
ReDim a(sendfilesize)
End Sub
Const sendfilesize = 1024 '发送文件块大小
Private Sub Command1_Click()
Dim a() As Byte
ReDim a(sendfilesize)
End Sub
追问
DoEvents
Dim a() As Byte
accept_filename = App.Path & "\" & App.EXEName & ".txt"
Open accept_filename For Binary As #1
If LOF(1) = 0 Then
List1.AddItem "数据到达lof(1)=0: " & bytesTotal
ReDim a(bytesTotal - 1)
Winsock1.GetData a
Put #1, 1, a
Else
List1.AddItem "数据到达lof(1)0: " & bytesTotal
ReDim a(bytesTotal - 1)
Winsock1.GetData a
Put #1, LOF(1) + 1, a
End If
Close
怎么改?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |