掉封包 問題 |
尚未結案
|
bebehome123
一般會員 ![]() ![]() 發表:13 回覆:4 積分:3 註冊:2004-11-16 發送簡訊給我 |
p2p都會掉封包
請幫我看看哪裡寫錯...
拜託 unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdTCPServer, IdHTTP, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, StdCtrls,strutils; type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
IdTCPClient1: TIdTCPClient;
IdHTTP1: TIdHTTP;
IdTCPServer1: TIdTCPServer;
procedure Button1Click(Sender: TObject);
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
var
i,ipos:integer;
filename :string ;
t4:tfilestream;
t1: tfilestream;
t2: string ;
sExtName : string ;
begin
IdTCPClient1.Host :=edit1.Text ;
IdTCPClient1.Port := 1111 ;
IdTCPClient1.Connect;
IdTCPClient1.WriteLn(edit2.Text );
if DirectoryExists('c:\知識管理')=false then
createdir('c:\知識管理');
if LeftStr(edit2.Text,7) = 'http://' then begin
for i:=length(edit2.Text)-1 downto 0 do begin
if edit2.Text[i]='/' then begin
ipos:=i;
break;
end;
end;
filename:=copy(edit2.Text,ipos+1,length(edit2.Text)-ipos);
t4:= tfilestream.Create('c:\知識管理\'+filename,fmCreate or fmShareExclusive);
idhttp1.Get(edit2.Text,t4);
showmessage('已經傳送到c:\知識管理\');
t4.Free;
IdTCPClient1.Disconnect;
end else begin
try
sExtName := ExtractFileName(edit2.Text);
if DirectoryExists('c:\知識管理')=false then
createdir('c:\知識管理');
t1:= tfilestream.create('c:\知識管理\'+sExtName, fmcreate or fmShareExclusive);
IdTCPClient1.ReadStream(t1, -1,true);
showmessage('已經傳送到c:\知識管理\');
finally
IdTCPClient1.Disconnect;
t1.free;
end;
end;
end;
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
t2 : tfilestream;
sExtName: String;
t3: string ;
begin
sExtName:= AThread.Connection.ReadLn() ;
if LeftStr(sExtName,7) = 'http://' then begin
sExtName:=sExtName;
end else begin
try
t2 := tfilestream.Create(sExtName,fmOpenRead or fmShareDenyNone);
t2.Seek(0,soFromBeginning);
AThread.Connection.OpenWriteBuffer;
AThread.Connection.WriteStream(t2);
AThread.Connection.CloseWriteBuffer;
finally
t2.Free;
end;
end;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
IdTCPServer1.DefaultPort := 1111;
IdTCPServer1.Active := true ;
end; end.
豬ㄚ你!!這麼簡單的東西...你都不懂......= =....誰叫我是新手呢...@ @ | ||
geniustom
版主 ![]() ![]() ![]() ![]() ![]() 發表:100 回覆:303 積分:260 註冊:2003-01-03 發送簡訊給我 |
bebehome123 您好.. 關於傳檔..請看一下這DDY大人的這篇文章..
【發表】網路下載檔案範例(Indy IdTCPServer/IdTCPClient) 含Source
http://delphi.ktop.com.tw/topic.php?topic_id=27733 還有..如果要貼程式碼麻煩請參考
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=7326
|
||
Ktop_Robot
站務副站長 ![]() ![]() 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |