[SOLVED] Indy 10 sending in 1024 byte chunks? How to increase? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- aidv · 2015-10-07 02:17 As the title suggests. How can I make it send more data at once? Sending 2MB of data takes like forever. ---------------------------------------------------------------------- balazsszekely · 2015-10-07 04:51 According to your previous thread you send/receive the data with writeln/readln: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i time := GetTickCount64;s := AContext.Connection.IOHandler.ReadLn('', IndyTextEncoding_Default, IndyTextEncoding_Default);log('ReadLn time: ' + inttostr(GetTickCount64 - time));As @Laksen and myself pointed out writeln/readln is designed to send small text not large binary data. For sending binary use the write/writestream method. Choosing the right send/receive protocol it greatly depends on the source data. Large text, pictures, etc... should be converted to stream other binary data to TIdBytes. Unfortunately without more info we just shot in the dark. ---------------------------------------------------------------------- aidv · 2015-10-07 12:32 @GetMem: Oh ok. Sorry for the lack of code in my question,  I took for granted that sending data would be handled automatically by Indy and not depend on which function you call. I am actually not using WriteLn, I am using just Write: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure SendData(aData: TMemoryStream);....ctx.Connection.IOHandler.Write(aData, aData.Size, false);  ....end; I have tried to set "IOHandler.SendBufferSize" to something higher, like 8000, but it still sends 1024 bytes. ---------------------------------------------------------------------- balazsszekely · 2015-10-07 14:18 Just send the stream size before the stream(see my example in your previous post). Alternatively you can set AWriteByteCount to True, if you want indy to handle the stream size for you. I prefer the first method because I can always double check the stream integrity if necessary. ---------------------------------------------------------------------- aidv · 2015-10-07 15:25 No no I think you've misunderstood me. Indy sends ANY data in 1024 byte long chunks. If I send a 2048 byte long data stream, it splits it in two and sends each chunk in 1024 bytes. If I send a 1 Megabyte data stream, it sends it in many 1024 byte chunks. I want Indy 10 to send larger chunks of data at once. EDIT: Here's a forum post from 2006 with the same problem as mine: http://www.delphigroups.info/2/4/212667.html ---------------------------------------------------------------------- balazsszekely · 2015-10-07 16:56 QuoteI think you've misunderstood me.Yes I did! So here is my answer: Indy does not change the default send/receive socket size. If you want to do it manually, you should call the setsockopt api(https://msdn.microsoft.com/en- us/library/ms740476%28VS.85%29.aspx). Take a look at SO_RCVBUF and SO_SNDBUF in particular. Setsockopt  is also available under linux. I think your problem is not the default packet size but something else. What do you mean by: "Sending 2MB of data takes like forever"? What is forever? For example I have a 50 Mbps connection, which is 6.25 MBs. After the TCP handshake,  it still requires at least 2MB/6.25Mbs = 0.32 sec to send the 2MB data.  In fact I just did a few test by connecting a remote Indy client to my local indy server. The average speed is 1 Mb/s . I calculated this by uploading a large file(few hundred Mb). ---------------------------------------------------------------------- aidv · 2015-10-07 17:30 I see, could you do a test for me and log the incoming data size? I send 2MB data from my linux server which uses Indy to a Mac XCode client, and on the XCode client I log the incoming data and it says "1024 bytes" until the end of the transmission. However when I send 2MB from my XCode client to my Indy Linux Server it (the Indy server) receives different lengths depending on how much space is available in the socket. Sending 2MB from Mac to Linux is very fast, up to 10 or even 20MB a second some times, but from Linux to Mac it's only up to 100 Kilobytes a second. And the reason for that is that Indy sends packets in 1024 byte chunks. ---------------------------------------------------------------------- balazsszekely · 2015-10-07 18:26 QuoteAnd the reason for that is that Indy sends packets in 1024 byte chunks.No is not! I never had speed issues with my client/server application. It's up and running for almost five years. Unfortunately without seeing the actual code I cannot tell you more. By the way what is the "XCode client"? Did you code the client in objective-c? If yes, how do you synchronize the client/server, because Indy is not a 100% complete wrapper around the socket API. I'm not saying it's impossible, nevertheless is a non-trivial task and maybe this is the bottleneck. Why don't you code the client in lazarus/indy? ---------------------------------------------------------------------- aidv · 2015-10-07 18:42 Did you try to log the incoming data size? Please do so, because i can see it right here and right now that the XCode client is receiving data in 1024 chunks. By the way, I used LNet instead of Indy a couple of weeks ago, and the 1024byte-chunk problem did not exist. I switched to Indy because Indy solved some of the problems I had with LNet. Yes I coded the client in objective-c, and I don't code the client in Lazarus/Indy because I have already been developing the ObjC app for 4, almost 5 months and am in my finale dev phase of it. ---------------------------------------------------------------------- balazsszekely · 2015-10-07 18:59 No, I did not try to log the data size,  but it's pretty obvious that won't be larger then 1500, because this is the default on windows. Just type the following command:"netsh interface ipv4 show subinterfaces". However that does not slow down you Indy client/server. ---------------------------------------------------------------------- aidv · 2015-10-07 19:08 But try it. Maybe you get different results. i'm sorry my friend, but I have to repeat myself. 1. When I used LNet, I did not have this problem, but with Indy I do. 2. I am on linux, not on windows. 3. Indy might be responsible for the "chunking", not necessarily, but I suspect Indy on this one. ---------------------------------------------------------------------- balazsszekely · 2015-10-07 19:51 @aidv Yes, you keep repeating yourself and I spend way to much time with this issue. I'm gonna detach myself from this thread,  there is no point to continue this way. PS: I hope you find the solution soon. ---------------------------------------------------------------------- aidv · 2015-10-07 20:00 Yeah, sorry for wasting time. I'm just trying to find a solution to fix this. It's weird to me why LNet did not behave like this and Indy does. Thanks. ---------------------------------------------------------------------- aidv · 2015-10-07 20:12 I dived in to the TCP class of my XCode iOS project and I found this very tiny one-line code which limits the input size. So it was not Indys fault after all. Still weird that I didn't have that problem when I used LNet though.