资源描述:
《高中信息技术教学论文 使用indy的IdTcpServer,IdTcpclient传输文件.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、使用indy的IdTcpServer,IdTcpclient传输文件 接受部分(有个用户和密码check,你取消就可以)procedureTTCP_Server.IdTCPServerExecute(AThread:TIdPeerThread);var FStream :TFileStream; FileName :String; CmdStr :String;begin CmdStr:=AThread.Connection.ReadLn(); ifCompareStr(Copy(CmdStr,1,6),'')=0then begin //1 D
2、elete(CmdStr,1,6); Cmd:='上传文件'; FileName:=CmdStr; ifFileExists(ExtractFilePath(Application.ExeName)+FileName)then DeleteFile(ExtractFilePath(Application.ExeName)+FileName); try FStream:=TFileStream.Create(ExtractFilePath(Application.ExeName)+FileName,FmCreate); AThre
3、ad.Connection.ReadStream(FStream,2048,true); Finally FStream.Free; AThread.Connection.Disconnect; end; end //1 elseifCompareStr(Copy(CmdStr,1,6),'')=0then begin //2 Delete(CmdStr,1,6); Cmd:='下载文件'; FileName:=CmdStr; ifFileExists(ExtractFilePath(Applicatio
4、n.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; 3用心爱心专心end; end
5、 else begin AThread.Connection.WriteLn('Failed'); AThread.Connection.Disconnect; end; end//2 elseifCompareStr(Copy(CmdStr,1,6),'')=0then begin //3 Delete(CmdStr,1,6); User:=UpperCase(Trim(DecryptString(CmdStr,20504)));//CmdStr; ifCompareStr(User,'XD
6、M')=0then begin Memo1.Lines.Add('User: '+User); CmdStr:=''; end else begin Memo1.Lines.Add('User: '+User+' 非法登陆,已关闭连接'); CmdStr:=''; AThread.Connection.WriteLn(''); AThread.Connection.Disconnect; end; end //3 elseifCompareStr(Copy
7、(CmdStr,1,6),'')=0then begin //4 Delete(CmdStr,1,6); Password:=DecryptString(CmdStr,20504);//CmdStr; ifCompareStr(Password,'123abc')=0then begin Memo1.Lines.Add('Login..........Accepted'); Memo1.Lines.Add('Connected......'+DateTimeToStr