Best way connecting to a server lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- GannTrader · 2015-08-03 10:38 Hi I need to connect to a server and wonder what is the best way of doing this. At the moment im using unit sockets with fpsocket, fpconnect and so on. I wonder if there is a more efficient way to connect to a server or if using sockets still is the best and fastest way to connect to a server? ---------------------------------------------------------------------- Graeme · 2015-08-03 11:13 What does your server do? Existing communication protocols have already been implement via the likes of the Indy or Synapse components - both free and open source. For a higher level, projects like tiOPF has a client/server and 3-tier implementation where you can save or load objects or list of objects with very little effort. All open source too. ---------------------------------------------------------------------- Thaddy · 2015-08-03 11:27 These higher level libraries are more convenient for the programmer, yes, but both - especially Indy! with its completely inapt use of exceptions for all and nothing, synapse less so - have a throughput penalty. If I understand your question it is: what gives me best performance? In that case, YES, sockets give you the best performance, especially near real-time performance if you know what you are doing. There aren't really any alternatives to sockets. All high level libs also use them. So from a throughput perspective: yes, sockets are still the way to go. ---------------------------------------------------------------------- GannTrader · 2015-08-03 11:29 I dont have a server. I want to connect to a server. My program is a client. I have tested Indy but when using readln to read what the server sends it dont funktion that well. Readln in other words contain bugs. Using sockets i dont get those errors i get with readln. ---------------------------------------------------------------------- GannTrader · 2015-08-03 11:30 Quote from: Thaddy on August 03, 2015, 01:27:57 pmThese higher level libraries are more convenient for the programmer, yes, but both - especially Indy! with its completely inapt use of exceptions for all and nothing, synapse less so - have a throughput penalty. If I understand your question it is: what gives me best performance? In that case, YES, sockets give you the best performance, especially near real-time performance if you know what you are doing. There aren't really any alternatives to sockets. All high level libs also use them. So from a throughput perspective: yes, sockets are still the way to go. I thought so just wondered if there were any newer/better way. ---------------------------------------------------------------------- Graeme · 2015-08-06 09:00 Quote from: GannTrader on August 03, 2015, 01:29:31 pmI have tested Indy but when using readln to read what the server sends it dont funktion that well. Readln in other words contain bugs. Or maybe your usage of it is wrong? I have used Indy for years under Delphi and FPC - using many of the existing protocols supplied. They tend to work very well. Have you asked this question in the Indy support lists? ---------------------------------------------------------------------- derek.john.evans · 2015-08-06 10:06 Quote from: Graeme on August 06, 2015, 11:00:31 amQuote from: GannTrader on August 03, 2015, 01:29:31 pmI have tested Indy but when using readln to read what the server sends it dont funktion that well. Readln in other words contain bugs. Or maybe your usage of it is wrong? I have used Indy for years under Delphi and FPC - using many of the existing protocols supplied. They tend to work very well. Major Ditto! Indy all the way! Used it for at least 12 years since Delphi 7. Used it in C# apps, Linux (Kylix) and Lazarus. Just forget about trying to "install" it. Its not required or recommend IMHO. Just use the unit name for the client/server you want and create components as need be. Most of the time I found I inherited from a Indy class anyway and overrided methods. Just my 2 cents. ---------------------------------------------------------------------- GannTrader · 2015-08-10 18:55 Im not saying that Indy is buggy but i am saying that the funktion ReadLn is. It happens that ReadLn missis what the server sends, very rare but it happends from time to time. Since i change to unit Sockets and using fprecv to catch what the server sends such missis has never happend. Below is the code i used when using ReadLn, i connected first. I didnt change any other code when going from ReadLn to fprecv and that indicates to me that theres something wrong with ReadLn. I dont remember if the thread locked on the ReadLn row or if it just missed a string send by the server. procedure Somethread.Execute; var message:string; begin while not terminated do    begin    message:=TCPClient.IOHandler.ReadLn;    //Do something with message;    end; end;