TCP With Indy lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- facom4ever · 2012-02-09 16:22 Hi boys & girls, I am using Indy IdTCPServer & IdTCPClient sockets. I try sending text from Client to Server like this :   with IdTCPClient do   begin     Connect;     IOHandler.WriteLn('TRANSFERTFILE');     IOHandler.WriteLn('test.txt');     IOHandler.WriteLn('content');     Disconnect;   end; And onExecute even server side I try to read the messages and create a file with content :   with AContext.Connection do   begin     Test := IOHandler.ReadLn;     if SameText(Test, 'TRANSFERTFILE') then     begin       Test := IOHandler.ReadLn;       AssignFile(MyFile, Test);       ReWrite(MyFile);       Test := IOHandler.ReadLn;       WriteLn(MyFile, Test);       CloseFile(MyFile);     end;     Disconnect;   end;  The problem is that the server reads TRANSFERTFILE, and that is all. It doesn't try to read the next lines, and strange it doesnt create my file even calling it TRANSFERTFILE. Isn't that weird ? Or am I missing something ? Thanks mates ---------------------------------------------------------------------- everton · 2012-02-09 17:22 Probably is getting out in that if. Try to do Trim in the response. ---------------------------------------------------------------------- facom4ever · 2012-02-10 07:38 It seems that it enters in the if... But Test variable is always equald transfertfile even after 2nd readln ---------------------------------------------------------------------- JD · 2012-02-10 09:32 Hi there. You're just sending strings from the client to the server. Suggest that you read http://delphi.about.com/od/indy/Internet_Direct_ Indy_knowledge_base.htm to get an overview of how to use Indy ---------------------------------------------------------------------- facom4ever · 2012-02-10 13:06 I don't know, the way it works is a bit strange. The client send (it sends one time each, checked with tcpdump) writeln(TRANSFERTFILE) writeln(dr.txt) writeln(contenu) The server onexecute event reads the data and puts in a memo. Here are the results... TRANSFERTFILE TRANSFERTFILE dr.txt TRANSFERTFILE dr.txt contenu TRANSFERTFILE dr.txt contenu TRANSFERTFILE dr.txt contenu TRANSFERTFILE dr.txt contenu Why it doesn't simple get ? TRANSFERTFILE dr.txt contenu ---------------------------------------------------------------------- facom4ever · 2012-02-13 09:00 Any idea Now it reads twice each message... ---------------------------------------------------------------------- facom4ever · 2012-02-13 10:32 Honestly I don't understand. I just want to exchange some simple text, why is it so complicated ? On windows with delphi it was so easy, even on very old versions. From client: procedure TForm1.Button3Click(Sender: TObject); begin   IdTCPClient1.Host := Edit1.Text;   IdTCPClient1.Connect;   IdTCPClient1.IOHandler.WriteLn('TRANSFERTFILE');   IdTCPClient1.IOHandler.WriteLn('dr.txt');   IdTCPClient1.IOHandler.WriteLn('contenu');   IdTCPClient1.Disconnect; end; On the server: procedure TForm1.IdTCPServer1Execute(AContext: TIdContext); var   Cmd : String; begin   with AContext.Connection.IOHandler do   begin     Test := ReadLn;     Cmd := Fetch(Test);     if Cmd = 'TRANSFERTFILE' then     begin       Test := ReadLn;       Memo1.Lines.Add(Fetch(Test));       Test := ReadLn;       Memo1.Lines.Add(Fetch(Test));     end;   end;   AContext.Connection.Disconnect; end;          And I get this : dr.txt contenu dr.txt contenu It is not logical I think ---------------------------------------------------------------------- joseme · 2012-02-13 11:21 May be this can help you. Code: [Select]function DownloadFile(OrigFile, DestFile: String): Boolean; var f:tfilestream;   IdHTTP1: TIdHTTP; begin   IdHTTP1 := TIdHTTP.Create(nil);   f:=tfilestream.create(destFile, fmcreate);   try     idhttp1.head(origFile);   // To know if the file already exists     idhttp1.get(origFile, f); //if file exists, download it   except     ShowMessage('El archivo '+origFile+' does not exist or is not downloadable');     Result := False;   end;     freeandnil(f);     IdHTTP1.Destroy; end; function SendFile(OrigFile, DestFile: String): Boolean; var   IdFTP1: TIdFTP; begin   Result := False;   IdFTP1 := TIdFTP.Create;   IdFTP1.Username:= 'name' ;   IdFTP1.Password:= 'pass';   IdFTP1.Host:= 'ftp.abcd.com'; //  IdFTP1.Passive:= True;   try     IdFTP1.Connect;     IdFTP1.Put(OrigFile, destFile, False);     Result := True;   finally     IdFTP1.Quit;     IdFTP1.Destroy;   end; end; ---------------------------------------------------------------------- facom4ever · 2012-02-13 15:12 Thank you at least I may send files.... But I still don't get why I receive twice all messages from the client that sends only one time  . That's absolutly insane. It's like there was two threads from de same client. ---------------------------------------------------------------------- facom4ever · 2012-02-14 08:58 I think I will simply give up doing networking applications with Lazarus on Mac So many time juste to fail to figure out how to send text messages betwin 2 terminals looks S.F. I don't understand why on Windows with VisualStudio or Delphi it was so easy, and now on MAc with Lazarus it looks impossible and unreliable. Thanks anyway for the help. ---------------------------------------------------------------------- User137 · 2012-02-14 12:29 http://wiki.lazarus.freepascal.org/Indy_with_Lazarus QuoteWhat works, what not Indy9: Windows should largely work. Lots of demoes ported. Linux not or barely. No hope at non Linux/x86 (non-Kylix) targets. Indy10: Windows and Unix: clients work and servers should work fine in principle. The main work for native Unix RTL done. Servers Clients seem to work with FreeBSD and OS X I might be interested at the Indy 10. If the use code really is that simple, it is million years ahead of Synapse that i have trouble with. ---------------------------------------------------------------------- facom4ever · 2012-02-15 09:38 Have you tried Indy10 ? The installation at least works on Mac 10.6.8