Winsock怎么发送大文件
怎么用VB的Winosck发送一个大于8KB的文件。怎么分割文件? --------------------编程问答-------------------- 这也是大文件?数组发送…… --------------------编程问答--------------------
可以具体点吗? --------------------编程问答--------------------
lngFile = FileLen(FileName) \ 8192 '取得文件长度部分代码。
For i = 0 To lngFile
ReDim myfile(8191) As Byte '初始化数组
Open FileName For Binary As #1 '打开文件
Get #1, i * 8192 + 1, myfile '将文件写入数组
Close #1 '关闭文件
WinsockTcp.SendData myfile '发送
DoEvents
Next i
楼主可搜下,网上有实例 --------------------编程问答--------------------
网上的实例太复杂了,而且我是UPD,可以告诉我接受的事件呢? --------------------编程问答-------------------- UDP属于发送后不管的,对于文件传输不太靠谱。
Open MyPath For Binary As #1 '新建文件接收端重建文件部分代码 --------------------编程问答-------------------- LS的不行呀 --------------------编程问答-------------------- Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
MyLong = FileLen(MyPath)
Put #1, MyLong + 1, myfile '将收到的数据写入新文件中
Close #1
……
End Sub
--------------------编程问答--------------------
全部改过的 有错误 --------------------编程问答-------------------- --------------------编程问答-------------------- 我还以为8G呢?8K很容易发送。 --------------------编程问答--------------------
帮个忙吗
--------------------编程问答-------------------- 你不会把你代码放出来给大家看看有啥错误?
你让大家猜谜呢…… --------------------编程问答--------------------
没代码呀!baidu了好长时间都没个能用的 --------------------编程问答-------------------- 大侠啊,你要把你报错的代码贴出来供大家检查检查……
既然报错,怎么会没代码…… --------------------编程问答-------------------- dd = 1
FileName = pas
lngFile = FileLen(FileName) \ 8192 '取得文件长度
For Ia = 0 To lngFile
ReDim myfile(8191) As Byte '初始化数组
Open FileName For Binary As #1 '打开文件
Get #1, Ia * 8192 + 1, myfile '将文件写入数组
Close #1 '关闭文件
Winsock1.SendData myfile '发送
DoEvents
Next Ia
'''''''''''''''''''''''''''''''''''''''''''''''''''
Kill Path & "pic.bmp"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim myfile As String
Winsock1.GetData myfile
Open Path & "123a.jpg" For Binary As #1 '新建文件
MyLong = FileLen(Path & "123a.jpg")
Put #1, MyLong + 1, myfile '将收到的数据写入新文件中
Close #1
End Sub --------------------编程问答-------------------- dd = 1
FileName = pas
lngFile = FileLen(FileName) \ 8192 '取得文件长度
For Ia = 0 To lngFile
ReDim myfile(8191) As Byte '初始化数组
Open FileName For Binary As #1 '打开文件
Get #1, Ia * 8192 + 1, myfile '将文件写入数组
Close #1 '关闭文件
Winsock1.SendData myfile '发送
DoEvents
Next Ia
'''''''''''''''''''''''''''''''''''''''''''''''''''
Kill Path & "pic.bmp"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim myfile As String
Winsock1.GetData myfile
Open Path & "123a.jpg" For Binary As #1 '新建文件
MyLong = FileLen(Path & "123a.jpg")
Put #1, MyLong + 1, myfile '将收到的数据写入新文件中
Close #1
End Sub
就是这个代码 --------------------编程问答-------------------- http://www.m5home.com/blog/article.asp?id=169
简单的例子.
大于100M时,需要用别的办法了. --------------------编程问答-------------------- 最大3M --------------------编程问答-------------------- socket发送文件时,跟文件的大小没有半毛钱的关系,只跟接收端有关。接收端需要判断这次(下次)接收到的数据是否还是该文件的数据,来确定是否写入文件。 --------------------编程问答--------------------
怎么弄? --------------------编程问答-------------------- 真服了,我17楼不是连整套方案都给出了么?你那啥文件啊,还传不了?? --------------------编程问答--------------------
我是UDP...... --------------------编程问答-------------------- UDP那不更简单么? --------------------编程问答-------------------- --------------------编程问答--------------------
帮个忙,我是新手 --------------------编程问答-------------------- 高度怀疑(帖子飞计划?) --------------------编程问答--------------------
.... --------------------编程问答-------------------- ding --------------------编程问答-------------------- 一个字节 一个一个的发送嘛,只不过麻烦点
补充:VB , 控件