資源描述:
《linux下http協(xié)議 多線程下載實(shí)現(xiàn)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、linux下http協(xié)議多線程下載實(shí)現(xiàn)該程序只能在http協(xié)議下工作,等以后研究其他協(xié)議時(shí)再補(bǔ)充。??-E'?!K+Z9y2^5K2s*r!a"j(I,G.E??J-F(%M,P.](網(wǎng)絡(luò)服務(wù)器用的是騰訊公司的linuxqq希望他們能原諒我……)3b,W0?*k"V%]9p-編程思路:??2x&s;?8b!}:z??q!r-V1、分析http協(xié)議數(shù)據(jù)包。??6I,h-O.P2N'R9R-G1Z以下是一個(gè)請(qǐng)求報(bào)文與相應(yīng)的回復(fù)報(bào)文的例子??,j+?)l0]/i;y9P,S,~"Y??E-h.j"o1[2e.~GE
2、T/linuxqq/linuxqq-v1.0.2-beta1.i386.rpmHTTP/1.1??,?"q8Z2r;l(v9RAccept:*/*??8L0G:I9y,g'n(TAccept-Language:en-us??*R9v7q1m:{-p9FUser-Agent:Mozilla/4.0(compatible;MSIE5.01;WindowsNT5.0)??$z??K!~5X"F??A:h*w)i8jHost::80????H8};p-G)e)R/w8{){9HConnection:Keep-Alive?
3、?#t2k3X/?&c-c5C.Z.F0J2X*_;P/`){9`HTTP/1.1206PartialContent??:U*c4w:u!w'v!c,HContent-Length:1009349??)l4q:j4{/E??KContent-Range:bytes0-1009348/5046743??;q4C5V3O$c&G%U/@Server:qqdlsrv(1.84forlinux)??.q&r3X*O"d+U*J7i??XConnection:Keep-alive??3F;b??h6S/f,x2w3
4、Con
5、tent-Disposition:attachment;filename=linuxqq-v1.0.2-beta1.i386.rpm??%?.C9X#?9k.U0y*i8Z$cAccept-Ranges:bytes??#o"t0p3q4K1c!Y6jContent-Type:application/octet-stream??9K,y"k&E)f6H$z${7h0Q;r.K:b9m$e1?$H$D,G;k;U2、取得文件大小,然后進(jìn)行對(duì)文件的分塊。??)T1{*^'r1I3Z2@3、對(duì)文件分塊下載??,S%d:m
6、1J7M,s.U4、合并文件,并改名。!y)[3d%L+D5B&A(w)L9P8p,w??q$v+A,[;w6B總結(jié):這個(gè)分塊再合并總感覺太過于啰嗦。??6A0P3L+W'E.r,v5u是否還有另外一種方法,??7^0%p%p't&r1Y#R;v(`如迅雷,在一開始就取得文件大小就在硬盤分配空間,??6D??M0]%E+C"C5m)c%E然后分塊下載直接寫入到文件的不同塊???2A"i2g6?9G0i是否可以用文件指針鎖住不同的區(qū)域并寫入?"y5s8n5L,a%z8b??F9Y:
7、;
8、't#q:x;O8~9M#
9、^*A??`&[9u%P7x:c,L!V3v/*??#w:B-m*p2I#k6S+}3^+r*down.c??2d2W8H4G3C9w*??!g$c,D0E,w6f,j7P!w*??Createdon:Mar27,2009??3S(x-L%j5l9o-u*????Author:root??:i&@!?.J#B%h!J'C*thisprogramistodownloadfileinhttpprotocolwithmultthreading??(v&d)e!q;]:y#r!
10、8K5W??i*/??0[.k.i&f-E
11、.p0o0r9U$L6Z#ifndefSTRUCT_H_??%h&^9v2q2`3J/b#defineSTRUCT_H_??3U3f%`'w$i:B2Q(d%K??R??J,`*Y0u!m1j!?8G#endif/*STRUCT_H_*/??5t0N4H'T*k&r&_3E8V#include??!y"U9o9i'F-p#include??&h9a,`3z2o:p8I)x4H!y5K#include??.[1?$]"z6n#W+a#include12、ng.h>??&F.F3q9K*D"G#include??2z(o!^+
13、,]#include??6P+`+g6I7k9t4z3v#include????K#s:p7e)@9C:N'V#include??&z4z&z!K&F!z//createastructtosaveth