有关Socket传输二进制文件问题

ouyi0901 2003-03-14 04:45:03
我用Socket传输二进制文件(如Gif,JPEG图形文件)总是出错,传输后的文件打不开
后来发现在用如下代码时
dim strText() as byte
Open strFileName For Binary As #nFile
strText = String(LOF(nFile), " ")
Get #nFile, , strText
Close #nFile

strText得到的内容与源 文件的内容有差异,不知道是什么道理
望高手指点
...全文
54 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
CsdnPlayer 2003-03-22
  • 打赏
  • 举报
回复
gz
落伍者 2003-03-21
  • 打赏
  • 举报
回复
默认情况下 ,winsock的可以发送4096个字节的数据。
cai12345 2003-03-19
  • 打赏
  • 举报
回复
你的程序是有点问题,因为winsock一次能传的数据是一个最大值的。 如果你要传输的话,就要把你的文件分成几块,每次只能传一块。
ex:如果文件长1024*5+36 bytes的话,若以1024 bytes为一块,就分成6部分,
dim strText() as byte
redim strtext(1023) as byte
open file for binary as #1
for i=0 to 4
get #1,,strtext()
wsk.senddata strtext
next i
redim strtext(35) as byte
get #1,,strtext()
wsk.senddata strtext()

接受端:
dim buf() as byte
wsk.getdata buf()
put #2,,buf

大概就是这样吧。


ouyi0901 2003-03-17
  • 打赏
  • 举报
回复
谢谢各位的回答
我用代码
dim strText() as byte
Open strFileName For Binary As #nFile
redim strText(LOF(nFile)-1) as byte
Get #nFile, , strText
Close #nFile
试了一下,好像还是不对;
cai12345(cai)的回复,能详细点吗,谢谢!
cai12345 2003-03-15
  • 打赏
  • 举报
回复
传的时候:
dim a as byte 随后用get ,在用senddata a
接的时候:
dim b as byte,然后getdata b,再用put
两个文件都用二进制打开
不过这样较慢,最好用chunk
onionertou 2003-03-15
  • 打赏
  • 举报
回复
strText = String(LOF(nFile), " ")错了
文本文件你还可以打开,如果是jpeg,bmp你错1bit就玩完了
ltpao 2003-03-14
  • 打赏
  • 举报
回复
dim strText() as byte
Open strFileName For Binary As #nFile
redim strText(LOF(nFile)-1) as byte
Get #nFile, , strText
Close #nFile

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧