资源描述:
《使用indy的idtcpserver,idtcpclient传输文件论文》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、使用indy的IdTcpServer,IdTcpclient传输文件论文.freel:TFileStream;FileName:String;CmdStr:String;beginCmdStr:=AThread.Connection.ReadLn();ifpareStr(Copy(CmdStr,1,6),'SEND')=0thenbegin//1Delete(CmdStr,1,6);Cmd:='上传文件';FileName:=CmdStr;ifFileExists(ExtractFilePath(
2、Application.ExeName)+FileName)thenDeleteFile(ExtractFilePath(Application.ExeName)+FileName);tryFStream:=TFileStream.Create(ExtractFilePath(Application.ExeName)+FileName,FmCreate);AThread.Connection.ReadStream(FStream,2048,true);FinallyFStream.Free;ATh
3、read.Connection.Disconnect;end;end//1elseifpareStr(Copy(CmdStr,1,6),'AGET')=0thenbegin//2Delete(CmdStr,1,.freeld:='文件';FileName:=CmdStr;ifFileExists(ExtractFilePath(Application.ExeName)+FileName)thenbegintryFStream:=TFileStream.Create(ExtractFilePath(
4、Application.ExeName)+FileName,FmOpenRead);AThread.Connection.')=0thenbeginMemo1.Lines.Add('User:'+User);CmdStr:='';endelsebeginMemo1.Lines.Add('User:'+User+'非法登陆,已关闭连接');CmdStr:='';AThread.Connection.emo1.Lines.Add('Connected......'+DateTimeToStr(NodS
5、tr:='';AThread.Connection.emo1.Lines.Add('PassdStr:='';AThread.Connection.Disconnect;end;end;//4end;主要发送部分procedureTTCP_Client.BtnSendClick(Sender:TObject);varFStream:TFileStream;beginifIdTcpClient.ConnectedthenbeginIdTcpClient.essageBox(Handle,'没有选择文
6、件','Error',MB_OK)elsebegintryFStream:=TFileStream.Create(FileName,FmOpenRead);FStream.Position:=0;FStream.Seek(0,0);IdTcpClient.emo1.Lines.Add('TransferredOK');end;endelsebeginMessageBox(Handle,'没有连接服务器','Error',MB_Ok);end;end;