Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7583233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:37:47+00:00 2026-05-30T18:37:47+00:00

I’m using an idTCPServer for processing data. For a new device I need to

  • 0

I’m using an idTCPServer for processing data.
For a new device I need to hand over the socket to a dll (stop the tcp server to read from that socket).

Is that possible with Indy or ICS?

[Edit]
For test purposes I made a thread instead of using the dll, because the lack of hardware.

  procedure TfrmIndyMain.IdTCPServer1Connect(AContext: TIdContext);
  begin
    FMyThread := TMyThread.Create(true);
    FMyThread.FSocket := AContext.Binding.Handle;
    FMyThread.Resume;
  end;  

  procedure TfrmTest.IdTCPServer1Execute(AContext: TIdContext);
  begin
    // Its necessary that indy stop reading from the socket, without reset a lot of messages is lost
    AContext.Binding.Reset(false); //not sure if this is correct
  end;

  procedure TMyThread.Execute;
  var
    len: integer;
    data: string;
  begin
    ioctlsocket(FSocket, FIONREAD, len);
    if len>0 then
    begin
      Setlength(data, len);
      if recv(FSocket, pointer(data)^, len, 0) <> SOCKET_ERROR then
        Log('Data: ' + data)
      else
        Log('Error');
    end;
  end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:37:48+00:00Added an answer on May 30, 2026 at 6:37 pm

    In Indy, you can use the TIdPeerThread.Connection.Binding.Socket property (Indy 9 and earlier) or the TIdContext.Connection.Socket.Binding.Handle property (Indy 10 – shortcut as TIdContext.Binding.Handle) to access the underlying SOCKET handle.

    Update: Indy maintains an InputBuffer of data that is read from the socket during Indy-based reading operations. That includes calls to TIdTCPConnection.Connected(), which TIdTCPServer calls in between successive triggers of the OnExecute event. So it is possible that you do not see all of the data that is on the socket because you are not looking at the InputBuffer for cached data. To avoid that, you would have to make sure the event only triggers once by running your own reading loop inside the event and avoid calling any of Indy’s reading methods, eg:

    procedure TfrmTest.IdTCPServer1Execute(AContext: TIdContext);
    var
      ret: Integer;
      data: AnsiString;
      tv: timeval;
      fd: fd_set;
    begin
      repeat
        FD_ZERO(@fd);
        FD_SET(AContext.Binding.Handle, @fd);
        tv.tv_sec := 1;
        tv.tv_usec := 0;
        ret := select(0, @fd, nil, nil, @tv);
        if ret = SOCKET_ERROR then
        begin
          Log('Error on select()');
          Break;
        end;
        if ret = 0 then Continue;
        ret := ioctlsocket(AContext.Binding.Handle, FIONREAD, len);
        if ret = SOCKET_ERROR then
        begin
          Log('Error on ioctlsocket()');
          Break;
        end;
        if len < 1 then Break;
        SetLength(data, len);
        len := recv(AContext.Binding.Handle, Pointer(data)^, len, 0);
        if len = SOCKET_ERROR then
        begin
          Log('Error on recv()');
          Break;
        end;
        SetLength(data, len);
        Log('Data: ' + data);
      until (some stop condition);
      AContext.Connection.Disconnect;
    end;
    

    If possible, a better solution would be to change your logic to not need to access the socket directly anymore. Let Indy do all of the reading normally, and then pass any received data to the rest of your code for processing, eg:

    procedure TfrmTest.IdTCPServer1Execute(AContext: TIdContext);
    var
      data: TMemoryStream;
    begin
      with AContext.Connection.IOHandler do
      begin
        if InputBufferIsEmpty then
        begin
          CheckForDataOnSource(1000);
          CheckForDisconnect(True);
          if InputBufferIsEmpty then Exit;
        end;
      end;
      data := TMemoryStream.Create;
      try
        with AContext.Connection.IOHandler do
          ReadStream(data, InputBuffer.Size, False);
        // use data.Memory up to data.Size bytes as needed...
      finally
        data.Free;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.