| 发表于:2007-03-07 18:43:32 楼主 |
做一个局域网内的下载功能,现在会出现客户端收到的文件比源文件小的情况。哪位能帮我看看,谢谢。 服务器端发送程序: sub sendfiletoclient(xfilename as string, ipaddy as string, whichwinsock as winsock) on error goto errorhandler dim buffer as string dim buffersize as integer dim filelength as long, superbuffer as long, timeout as long dim i as integer dim j as integer buffersize = 2048 do while whichwinsock.state <> 7: doevents if whichwinsock.state = sckerror then writeerrlog "winsock error: " & vbcrlf & err.description: exit sub end if loop startsending = false whichwinsock.senddata "filesize= " & filelen(xfilename) do while startsending <> true doevents loop i = freefile 'find free file open xfilename for binary access read as #i filelength = lof(i) do while not eof(i) doevents if filelength - loc(i) < buffersize then let buffersize = filelength - loc(i) if buffersize = 0 then goto done end if 'buffer = space(buffersize) redim abuf(0 to buffersize - 1) get #i, , buffer whichwinsock.senddata buffer) superbuffer = superbuffer + len(buffer) '等待客户端接受以后再发 do while (timeout < 10000) doevents timeout = timeout + 1 if timeout > 10000 then exit do loop 'debug.print j timeout = 0 loop done: close #i whichwinsock.senddata "sendend " do while (timeout < 10000) doevents timeout = timeout + 1 if timeout > 10000 then exit do loop startsending = false writeerrlog "sent ' " & xfilename & " ' ( " & superbuffer & " bytes) to ip ' " & ipaddy & " ' time/date= " & format(now, "yyyy/mm/dd hh:mm:ss ") exit sub errorhandler: writeerrlog "sent ' " & xfilename & " 'to ip ' " & ipaddy & " ' time/date= " & format(now, "yyyy/mm/dd hh:mm:ss ") & "出现错误: " & err.description end sub 客户端接收 private sub winsock_dataarrival(byval bytestotal as long) dim data as string dim receivearr() as byte if winsock.state <> 7 then exit sub call winsock.getdata(data, , bytestotal) if left(data, 6) = "error: " then blnerror = true fcomplete = true exit sub end if if left(data, 9) = "filesize= " then filesize = right(data, len(data) - 9) inr = 1 if filesize = 0 then close #filenum fcomplete = true exit sub end if call client.senddata( "begin ") exit sub end if if data = "sendend " then close #filenum fcomplete = true exit sub end if if filenum > 0 then put #filenum, , data 'debug.print inr inr = inr + 1 if lof(filenum) = filesize then close #filenum fcomplete = true exit sub end if end if end sub |
|
|
|
|