1、计算机论文:使用 indy 的 IdTcpServer,IdTcpclient 传输文件 接受部分(有个用户和密码 check,你取消就可以)procedure TTCP_Server.IdTCPServerExecute(AThread: TIdPeerThread);varFStream : TFileStream;FileName : String;CmdStr : String;beginCmdStr :=AThread.Connection.ReadLn();if CompareStr(Copy(CmdStr,1,6),)=0 thenbegin /1Delete(CmdStr,1,
2、6);Cmd := 上传文件;FileName := CmdStr;if FileExists(ExtractFilePath(Application.ExeName)+FileName) thenDeleteFile(ExtractFilePath(Application.ExeName)+FileName);tryFStream := TFileStream.Create(ExtractFilePath(Application.ExeName)+FileName,FmCreate);AThread.Connection.ReadStream(FStream,2048,true);Final
3、lyFStream.Free;AThread.Connection.Disconnect;end;end /1else if CompareStr(Copy(CmdStr,1,6),)=0 thenbegin /2Delete(CmdStr,1,6);Cmd := 下载文件;FileName := CmdStr;if FileExists(ExtractFilePath(Application.ExeName)+FileName) thenbegintryFStream := TFileStream.Create(ExtractFilePath(Application.ExeName)+Fil
4、eName,FmOpenRead);AThread.Connection.WriteStream(FStream,True,False);FinallyFStream.Free;AThread.Connection.Disconnect;end;endelsebegin 计算机论文AThread.Connection.WriteLn(Failed);AThread.Connection.Disconnect;end;end /2else if CompareStr(Copy(CmdStr,1,6),)=0 thenbegin /3Delete(CmdStr,1,6);User := Upper
5、Case(Trim(DecryptString(CmdStr,20504); /CmdStr;if CompareStr(User,XDM)=0 thenbeginMemo1.Lines.Add(User: +User);CmdStr :=;endelsebeginMemo1.Lines.Add(User: +User+ 非法登陆,已关闭连接);CmdStr := ;AThread.Connection.WriteLn();AThread.Connection.Disconnect;end;end /3else if CompareStr(Copy(CmdStr,1,6),)=0 thenbe
6、gin /4Delete(CmdStr,1,6);Password := DecryptString(CmdStr,20504); /CmdStr;if CompareStr(Password,123abc)=0 thenbeginMemo1.Lines.Add(LoginAccepted);Memo1.Lines.Add(Connected+DateTimeToStr(Now);CmdStr := ;AThread.Connection.WriteLn();endelsebeginMemo1.Lines.Add(Password Wrong.Login Failure);AThread.Co
7、nnection.WriteLn();CmdStr :=;AThread.Connection.Disconnect;end;end; /4end; 主要发送部分procedure TTCP_Client.BtnSendClick(Sender: TObject);varFStream : TFileStream;beginif IdTcpClient.Connected then beginIdTcpClient.WriteLn(+ExtractFileName(FileName);if FileName = thenMessageBox(Handle,没有选择文件,Error,MB_OK)
8、else begintryFStream := TFileStream.Create(FileName,FmOpenRead);FStream.Position := 0;FStream.Seek(0,0);IdTcpClient.WriteStream(FStream,true,false);FinallyFStream.Free;IdTcpClient.Disconnect;end;Memo1.Lines.Add(Transferred OK);end;endelsebeginMessageBox(Handle,没有连接服务器,Error,MB_Ok);end;end; 本文由无忧论文网(会计)发表中心独家提供资源,如有雷同,纯属盗版。欢迎各位光临获取更多有用资料。无忧论文网:http:/教育论文网:http:/第一论文网 http:/核心论文发表网:http:/www.51fabiao.org古玩网 http:/www.china- http:/www.china- http:/ http:/ http:/ http:/ http:/ http:/ http:/ http:/ QQ:357500023 发表:15221741752 QQ:869156324