Search code examples
delphiindy

TidTCPServer Upgrade Problems


I've recently needed to upgrade an old Delphi 6 project to Delphi 2007. It is a server application using the Indy TidTCPServer component. I've followed all the examples I could find on upgrading to Indy 10.

The application interfaces with an old VB6 application (that we do not have the code for) via TCP/IP. I'm having a difficult time because the Execute event on the Indy component fires as soon as the VB6 application connects, but it does not write any data. This causes the application to hang waiting for the application to send data that never arrives.

The original code looked like:


data := AContext.Connection.IOHandler.ReadLn;
if data <> '' then
  begin
    // do some stuff
  end;

I've tried several code examples from the Indy examples, as well as here on StackOverlow. An example is:

AContext.Connection.IOHandler.CheckForDataOnSource(10);
if not AContext.Connection.IOHandler.InputBufferIsEmpty then
  begin
    data := AContext.Connection.IOHandler.ReadLn();
    if data <> '' then
      begin
        // do some stuff
      end;
  end;

Strangely enough, the original code works flawlessly when I hit it with a .NET client. This only seems to be a problem coming from the VB6 application.


Solution

  • Problem solved. The following code works...

    
    AContext.Connection.IOHandler.CheckForDataOnSource(10);
      if not AContext.Connection.IOHandler.InputBufferIsEmpty then
        begin
          data := AContext.Connection.IOHandler.InputBuffer.Extract;
    

    After closely inspecting the stream (as suggested by @Roddy), I was able to determine that the VB6 application was not sending a CRLF on the connections, which was causing the AContext.Connection.IOHandler.ReadLn; to block waiting for a CRLF that never came.

    Thank you @Darian and @Roddy for helping me find the answer.