资源描述:
《使用indy的idtcpserver,idtcp》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、使用indy的IdTcpServer,IdTcp接受部分(有个用户和密码check,你取消就可以)procedureTTCP_Server.IdTCPServerExecute(AThread:TIdPeerThread);var FStream :TFileStream; FileName :String; CmdStr :String;begin CmdStr:=AThread.Connection.ReadLn(); ifpareStr(Copy(CmdStr,1,6),'<SEND&
2、gt;')=0then begin //1 Delete(CmdStr,1,6); Cmd:='上传文件'; FileName:=CmdStr; ifFileExists(ExtractFilePath(Application.ExeName)+FileName)then DeleteFile(ExtractFilePath(Application.ExeName)+FileName); try FStream:=TFileStream.Create(E
3、xtractFilePath(Application.ExeName)+FileName,FmCreate); AThread.Connection.ReadStream(FStream,2048,true); Finally FStream.Free; AThread.Connection.Disconnect; end; end //1 elseifpareStr(Copy(CmdStr,1,6),'<AGET>')=0then begin //2
4、 Delete(CmdStr,1,6); Cmd:='下载文件'; FileName:=CmdStr; ifFileExists(ExtractFilePath(Application.ExeName)+FileName)then begin try FStream:=TFileStream.Create(ExtractFilePath(Application.ExeName)+FileName,FmOpenRead); AThread
5、.Connection.')=0then begin Memo1.Lines.Add('User: '+User); CmdStr:=''; end else begin Memo1.Lines.Add('User: '+User+' 非法登陆,已关闭连接'); CmdStr:=''; AThread.Connection.emo1.Lines.Add('Connected......'+DateTimeToStr(Nod
6、Str:=''; AThread.Connection.emo1.Lines.Add('PassdStr:=''; AThread.Connection.Disconnect; end; end; //4end;主要发送部分procedureTTCP_Client.BtnSendClick(Sender:TObject);var FStream:TFileStream;begin ifIdTcpClient.Connectedthenbegin IdTcpClient
7、.essageBox(Handle,'没有选择文件','Error',MB_OK) elsebegin try FStream:=TFileStream.Create(FileName,FmOpenRead); FStream.Position:=0; FStream.Seek(0,0); IdTcpClient.emo1.Lines.Add('TransferredOK'); end; end else begin MessageBox
8、(Handle,'没有连接服务器','Error',MB_Ok); end;end;