91精品人妻互换日韩精品久久影视|又粗又大的网站激情文学制服91|亚州A∨无码片中文字慕鲁丝片区|jizz中国无码91麻豆精品福利|午夜成人AA婷婷五月天精品|素人AV在线国产高清不卡片|尤物精品视频影院91日韩|亚洲精品18国产精品闷骚

您當前位置:首頁 > 新聞頻道 > 技術動態(tài) > 正文
indy的IdTcpServer,IdTcpclient傳輸文件略談
 

接受部分(有個用戶和密碼check,你取消就可以)
procedure TTCP_Server.IdTCPServerExecute(AThread: TIdPeerThread);
var
 FStream  : TFileStream;
 FileName  : String;
 CmdStr   : String;
begin
  CmdStr :=AThread.Connection.ReadLn();
  if CompareStr(Copy(CmdStr,1,6),'<SEND>')=0 then
   begin //1
    Delete(CmdStr,1,6);
    Cmd := '上傳文件';
    FileName := CmdStr;
    if FileExists(ExtractFilePath(Application.ExeName)+FileName) then
      DeleteFile(ExtractFilePath(Application.ExeName)+FileName);
    try
     FStream := TFileStream.Create(ExtractFilePath(Application.ExeName)+FileName,FmCreate);
     AThread.Connection.ReadStream(FStream,2048,true);
    Finally
     FStream.Free;
     AThread.Connection.Disconnect;
    end;
   end  //1
  else if CompareStr(Copy(CmdStr,1,6),'<AGET>')=0 then
   begin //2
    Delete(CmdStr,1,6);
    Cmd := '下載文件';
    FileName := CmdStr;
    if FileExists(ExtractFilePath(Application.ExeName)+FileName) then
      begin
       try
        FStream := TFileStream.Create(ExtractFilePath(Application.ExeName)+FileName,FmOpenRead);
        AThread.Connection.WriteStream(FStream,True,False);
       Finally
        FStream.Free;
        AThread.Connection.Disconnect;
       end;
      end
    else
      begin
       AThread.Connection.WriteLn('Failed');
       AThread.Connection.Disconnect;
      end;
   end //2
  else if CompareStr(Copy(CmdStr,1,6),'<USER>')=0 then
   begin //3
    Delete(CmdStr,1,6);
    User := UpperCase(Trim(DecryptString(CmdStr,20504))); //CmdStr;
    if CompareStr(User,'XDM')=0 then
      begin
       Memo1.Lines.Add('User: '+User);
       CmdStr :='';
      end
    else
      begin
       Memo1.Lines.Add('User: '+User+' 非法登陸,已關閉連接');
       CmdStr := '';
       AThread.Connection.WriteLn('<Failed>');
       AThread.Connection.Disconnect;
      end;
   end  //3
  else if CompareStr(Copy(CmdStr,1,6),'<PASS>')=0 then
   begin //4


    Delete(CmdStr,1,6);
    Password := DecryptString(CmdStr,20504); //CmdStr;
    if CompareStr(Password,'123abc')=0 then
      begin
       Memo1.Lines.Add('Login..........Accepted');
       Memo1.Lines.Add('Connected......'+DateTimeToStr(Now));
       CmdStr := '';
       AThread.Connection.WriteLn('<Accepted>');
      end
    else
      begin
       Memo1.Lines.Add('Password Wrong...Login Failure');
       AThread.Connection.WriteLn('<Failed>');
       CmdStr :='';
       AThread.Connection.Disconnect;
      end;
   end;  //4
end;

主要發(fā)送部分
procedure TTCP_Client.BtnSendClick(Sender: TObject);
var
 FStream : TFileStream;
begin
 if IdTcpClient.Connected then begin
   IdTcpClient.WriteLn('<SEND>'+ExtractFileName(FileName));
   if FileName = '' then
    MessageBox(Handle,'沒有選擇文件','Error',MB_OK)
   else begin
      try
      FStream := TFileStream.Create(FileName,FmOpenRead);
      FStream.Position := 0;
      FStream.Seek(0,0);
      IdTcpClient.WriteStream(FStream,true,false);
      Finally
      FStream.Free;
      IdTcpClient.Disconnect;
      end;
      Memo1.Lines.Add('Transferred OK');
     end;
 end
 else
  begin
   MessageBox(Handle,'沒有連接服務器','Error',MB_Ok);
  end;
end;

關鍵字:通訊
About Us - 關于我們 - 服務列表 - 付費指導 - 媒體合作 - 廣告服務 - 版權(quán)聲明 - 聯(lián)系我們 - 網(wǎng)站地圖 - 常見問題 - 友情鏈接
Copyright©2014安裝信息網(wǎng) www.78375555.com. All rights reserved.
服務熱線:4000-293-296 聯(lián)系電話:0371-61311617 傳真:0371-55611201 QQ: 郵箱:zgazxxw@126.com 豫ICP備18030500號-4
未經(jīng)過本站允許,請勿將本站內(nèi)容傳播或復制
安全聯(lián)盟認證