Avatar of drtester
drtester

asked on 

How to set UseNagle to false in Delphi 7 / Indy 9

Hello,

I have an app written in Delphi 7 that is a TCP server, and must send realtime data immediately out the network port, with no delay.  I had been using a modified socket file, and had the TCP_NODELAY set, and all was well.  I recently switched to using Indy, and can't seem to get this working.  I understand I should set the UseNagle to false, but as you can see below, I *think* I have done this, yet it does not appear to work.

Here are the relevant portions of my code:

procedure TIndyTCPServer.InitServer;
begin
   FServerType := 'TCP';
   FServer := TIdTCPServer.Create(nil);
   with FServer do begin
      MaxConnections := FMaxConnections;
      DefaultPort := DEF_TCP_PORT;
      //TerminateWaitTime := 2000;
      OnConnect := ServerSocketConnect;
      OnDisconnect := ServerSocketDisconnect;
      OnExecute := ServerSocketExecute;
   end;
end;

procedure TIndyTCPServer.CloseServer;
begin
   StopServer;
   FServer.Free;
end;

procedure TIndyTCPServer.StartServer;
begin
   FServer.Active := True;
end;

procedure TIndyTCPServer.StopServer;
var
   Threads: TList;
   i: Integer;
begin
   try
      Threads := FServer.Threads.LockList;
      try
         for i := Threads.Count - 1 downto 0 do
            with TIdPeerThread(Threads.Items[i]).Connection do
               if Connected then
                  Disconnect;
      finally
         FServer.Threads.UnlockList;
      end;
      FServer.Active := False;
   except
   end;
end;

procedure TIndyTCPServer.TransmitBuffer(Connection: TObject; Buffer: Pointer; Count: Integer);
begin
   with TIdPeerThread(Connection) do
      if not Terminated and Connection.Connected then begin
         Connection.Socket.UseNagle:=False; // TCP NO_DELAY!
         Connection.WriteBuffer(Buffer^, Count, True);
         end;
end;

procedure TIndyTCPServer.ServerSocketConnect(AThread: TIdPeerThread);
begin
   // Save for easy access later
   AThread.Connection.Socket.UseNagle:=False; // TCP NO_DELAY!
   AThread.Data := AddRemote(AThread, AThread.Connection.Socket.Binding.PeerIP);
end;

procedure TIndyTCPServer.ServerSocketDisconnect(AThread: TIdPeerThread);
begin
   DeleteRemote(TRemote(AThread.Data));
   AThread.Data := nil;
end;

Open in new window


Ideas?
DelphiProgrammingInternet Protocols

Avatar of undefined
Last Comment
drtester
Avatar of Thommy
Thommy
Flag of Germany image

Try flushing your TCP write buffer (TIdTCPConnection.FlushWriteBuffer)...

Perhaps this may help...
Indy Write Buffering / Efficient TCP communication
Avatar of drtester
drtester

ASKER

I just tried adding it here:

ure TIndyTCPServer.TransmitBuffer(Connection: TObject; Buffer: Pointer; Count: Integer);
begin
   with TIdPeerThread(Connection) do
      if not Terminated and Connection.Connected then begin
       //  Connection.Socket.UseNagle:=False; // TCP NO_DELAY!
         Connection.WriteBuffer(Buffer^, Count, True);
         Connection.FlushWriteBuffer();
         end;
end;

...but it generated illegal read of address 0 errors on code following this.  

I did read that article, and it was one of the ones I saw that mentioned the UseNagle thing, but I'm running out of ideas on how to make it work.
ASKER CERTIFIED SOLUTION
Avatar of drtester
drtester

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of drtester
drtester

ASKER

No one provided a solution
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo