| 发表于:2007-01-29 21:06:11 楼主 |
客户端收到的bytestotal总的加起来正好是服务器端发送的文件的大小,但是我打开客户端文件夹,里面新生成的文件大小却为0字节! 莫名中!....... 客户端: dim bytdata() as byte 'public llenfile as long dim f as integer f = freefile on error goto rep1: debug.print getattr(xls_savefile) '通过获得文件属性出错判断文件是否存在 goto rep2: rep1: '如果文件不存在,则生成! open xls_savefile for binary as #1 close #1 rep2: open xls_savefile for binary as #f 'msgbox lof(f) redim bytdata(1 to bytestotal) client_winsock.getdata bytdata put #f, lof_f + 1, bytdata 'lof_f是一个全局变量, lof_f = lof_f + bytestotal close #f 服务器端: const imax = 5555 数据块的大小。 dim ff as integer '文件号 dim lenfile as long '文件的长度 dim bytdata() as byte '存放数据的数组 ff = freefile '获得空闲的文件号 open temp_path for binary as #ff '打开文件 doevents lenfile = lof(ff) '获得文件长度 if lenfile <= imax then '如果要发送的文件小于数据块大小,直接发送 redim bytdata(1 to lenfile) '根据文件长度重新定义数组大小 get #ff, , bytdata '把文件读入到数组里 close #ff '关闭文件 server_winsock(s_w_id).senddata bytdata '发送数据 now_s_w_id = -11 kill temp_path exit function end if '文件大于数据块大小,进行分块发送 do until (ipos > = (lenfile - imax)) '发送整块数据的循环 redim bytdata(1 to imax) get #ff, ipos + 1, bytdata server_winsock(s_w_id).senddata bytdata ipos = ipos + imax '移动ipos,使它指向下来要读的数据 loop '这里要注意的是,必须检查文件有没有剩下的数据,如果文件大小正好等于数据块大小的 整数倍,那么就没有剩下的数据了 if lenfile - ipos <= 0 then goto rep2: redim bytdata(1 to lenfile - ipos) '发送剩下的不够一个数据块的数据 get #ff, ipos + 1, bytdata server_winsock(s_w_id).senddata bytdata close #ff rep2: now_s_w_id = -11 kill temp_path |
|
|
|
|