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 8824585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:40:13+00:00 2026-06-14T06:40:13+00:00

I need to write a Delphi 2009 application, which reads data from a socket.

  • 0

I need to write a Delphi 2009 application, which reads data from a socket. To do this, I need to write an event handler for the TIdTCPServer.OnExecute event.

I found lots of examples for implementing this in GUI applications, but I need to do it in a console application (without any windows).

How should I modify the code below in order to add an event handler (attach it to TCPServer), which prints every received message into the debug output?

unit ReceivingThreadUnit;

interface

uses
  Classes,
  IdTCPServer,
  IdSocketHandle,

  SysUtils,
  Windows;

type
  ReceivingThread = class(TThread)
    private
      TCPServer: TIdTCPServer;
    public
      procedure Run();

  end;

implementation

procedure ReceivingThread.Run();
var
  Bindings: TIdSocketHandles;
begin
  TCPServer := TIdTCPServer.Create(nil);

  //setup and start TCPServer
  Bindings := TIdSocketHandles.Create(TCPServer);
  try
    with Bindings.Add do
    begin
      IP := '127.0.0.1';
      Port := 9998;
    end;
    try
      TCPServer.Bindings:=Bindings;
      // Here I want to attach TCPServer to an OnExecute event handler
      TCPServer.Active:=True;
    except on E:Exception do
      OutputDebugString(PChar(E.ToString));
    end;
  finally
    Bindings.Free;
    TCPServer.Free;
  end;
  TCPServer.Active := true;
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-06-14T06:40:14+00:00Added an answer on June 14, 2026 at 6:40 am

    You need to add an event handler to your class. And then connect it up:

    TCPServer.OnExecute := Self.ExecuteHandler;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a script in Matlab, which will read some data from
I need to write a Delphi application that pulls entries up from various tables
I need to read from and write to Excel spreadsheets using Delphi 2010. Nothing
I need to write a DLL (using Delphi) which is dynamically loaded into delphi
I have some delphi code which I need to migrate / port / re-write
The application need write file's last modification date. void Dater(String DateFile) { File file
I need to write some input data files for a python program, and I
I need to write a program in any programming language (preferably Delphi 7 /
I'm using Delphi 2007. I need write a FormatDateTime function that always return 01/01/
I'm trying to write bits of code to a Microsoft access database from Delphi.

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.