troubleshooting Question

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

Avatar of drtester
drtester asked on
ProgrammingDelphiInternet Protocols
4 Comments1 Solution2992 ViewsLast Modified:
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;

Ideas?
ASKER CERTIFIED SOLUTION
drtester

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros