Question

delphi tcp/ip client with onrecieve event

Asked by: T0masz

Hey, Im writing a program where i establish a connection between the client  program and the server and then the server sends the data as it comes. I refuse to use a timer to pull the data, i want a onrecieve event that I could use to pull the data. Is anyone aware of such a component? tcpclient from standard delphi 7 doesnt work... and indy(idtcpclient) doesnt have an event.

Tom

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-04-06 at 18:06:15ID21805009
Tags

delphi

Topic

Delphi Programming

Participating Experts
2
Points
500
Comments
6

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. 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.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Indy: Is it possible to...
    Hi! I use D5 and I think about migrating to Indy. Now I wonder if it is possible to avoid installing packages, patching the IDE etc. I think about something like putting the source code in a folder and use the components like TIndyWhatever.Create(Form1)... Any hint appreciat...
  2. Indy TCP Server
    I'm Using Indy (Indy sucks!!!!) and I want to send a string via TCP Server. In Delphi 3, with standard TCP Socket, that's really easy, but now, I use the "Writeln(stringtosend)" cmd. That works when I'm on a Socket Thread procedure, but I want to do this with a exte...
  3. Indy TCP (Client/Server)
    Greetings... I Need a very Clear example of how to send & receive(commands and string)using indy TCP Client, Server Client ? also the Server has a password to establish the connection from the client. thank you for your time.
  4. Sending/Recieving Records with Indy IdTCPServer/IdTCP…
    Hi, I have one client and one server that I have implemented with the indy components in Delphi 7. At the client end I need to send any one of three very different records to the server end. There are three buttons on the client end and each button corresponds to one of th...
  5. Secure Handshake WIth Delphi & Indy
    Hi All, What is the best way for a client to authenticate with a server using the TCP/IP components of Indy (standard TCP client and server components)? The server has a list of users and passwords, the client software needs to authenticate through the server with that list...
  6. 1000 Points for an INDY TCP Example
    Hello there, here's the deal, I need a nice and simple example of two small apps. App1 Will be a server using Indy TCP Server (an edit box can be used to show a message readed from a client) App2 Just a client using an Indy TCP Client that will be able to connect to the s...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: RickJPosted on 2006-04-06 at 18:17:16ID: 16397162

Look at the ICS components on this page,

http://www.overbyte.be/frame_index.html

I am fairly sure they will do what you want and are free!!

 

by: tobjectpascalPosted on 2006-04-06 at 19:41:22ID: 16397497

Both components are threaded if i recall (i still use Delphi 5, had Delphi 7 trial to playh with though)

In other words, they don't have events, linux does not have fd_read, fd_write fd_close, etc etc, when winsock encounters a message it sends the message to the application, your application reads the queue and gets fd_read, the function that deals with it then fires off the even FOnRecv(Self......) at which point your components tells you there's some data waiting.

Linux does not have this, so in order to keep compatability both the tcpclient and the indy don't support none blocking sockets, ie, you have to loop for the data.

Solution
---------

Delphi > Menu > Component > Install Packages

click on "Add"

C:\Program Files\Borland\Delphi7\Bin\dclsockets70.bpl

look for that and install it.

you will end up with a new internet component, ones' a server the other a client.

stick the Client on the form

ClientSocket1.Port:=666;
ClientSocket1.Host:='127.0.0.1';
ClientSocket1.Active:=True;

OnConnect..

procedure TForm1.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
begin

end;


procedure TForm1.ClientSocket1Read(Sender: TObject;
  Socket: TCustomWinSocket);
Var
   S: String;
begin
  S:=Socket.ReceiveText;
  ShowMessage(S);
end;


Etc etc, it's the easiest component to use and will always be the easiest, i hate indy.

 

by: T0maszPosted on 2006-04-06 at 23:44:37ID: 16398273

I couldnt install the additional component in my delphi 7

as for ICS I got most of the stuff to work, its almost perfect with one MAJOR problem. I can connect the first time but after disconnecting the server isnt listening on the port agian...

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, WSocket;

const
  WM_AUTO_START      = WM_USER + 1;
  WM_CLOSE_REQUEST   = WM_USER + 2;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Edit1: TEdit;
    WSocket1: TWSocket;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure WSocket1DataAvailable(Sender: TObject; ErrCode: Word);
    procedure Button2Click(Sender: TObject);
    procedure WSocket1SessionAvailable(Sender: TObject; ErrCode: Word);
    procedure WSocket1SessionClosed(Sender: TObject; ErrCode: Word);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function ReplaceChar (const Source : String; const Find, Replace: Char) : string;
var
  i: integer;
  B: PByteArray; // Attention: zero-based!
  Fi, Re: byte;
begin
  Fi := ord (Find);
  Re := ord (Replace);
  Result := Source;
  UniqueString (Result);
  B := @Result [1];
  { i starts at zero, because B is zero-based }
  for i := 0 to length (Result) - 1 do
    if B [i] = Fi then
      B [i] := Re;
end;


function HexToString(S: string): string;
var
  i: integer;
begin
  Result := '';
  for i := 1 to Length(S) do
    if ((i mod 2) = 1) then
      Result := Result + Chr( StrToInt( '0x' + Copy( S, i, 2 )));
end;

function StringToHex(S: string): string;
var
  i: integer;
begin
  Result := '';
  for i := 1 to Length(S) do
    Result := Result + IntToHex( Ord( S[i] ), 2 );
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
wsocket1.proto:='tcp';
wsocket1.port:=Edit1.Text;
wsocket1.addr:='0.0.0.0';
PostMessage(Handle, WM_AUTO_START, 0, 0);

wsocket1.LISTEN;
end;

procedure TForm1.WSocket1DataAvailable(Sender: TObject; ErrCode: Word);
var
  s: string;
  data : string;
begin
     data := Trim(wsocket1.ReceiveStr);
     Memo1.Lines.Add('Recv ASCII: ' + data);
     Memo1.Lines.Add('Recv   HEX: ' + StringtoHex(data));


    if data = 'E' then wsocket1.SendStr(HexToString(StringReplace('00 01 02 49 41 58',' ','',[rfReplaceAll, rfIgnoreCase]))+chr(13));
    if data = 'B' then wsocket1.SendStr(HexToString(StringReplace('54 6F 6D 20 4E 41 20 33 62 61 72 20 42 00 33 30 34 54 33 02',' ','',[rfReplaceAll, rfIgnoreCase]))+chr(13));
    if data = 'G' then wsocket1.SendStr(HexToString(StringReplace('53 31 31 33 30 32 38 30 44 45 31 38 30 30 34 34 30 35 42 39 30 30 33 32 46 41 30 41 37 31 46 46 30 30 41 31 45 36 30 41 33 42 0D 0A',' ','',[rfReplaceAll, rfIgnoreCase]))+chr(13));
    if data = 'A' then wsocket1.SendStr(HexToString(StringReplace('41 58',' ','',[rfReplaceAll, rfIgnoreCase]))+chr(13));
    if data = 'T' then wsocket1.SendStr(HexToString(StringReplace('FF FF FF FF FF FF FF FF FF FF FF FF 41 58',' ','',[rfReplaceAll, rfIgnoreCase]))+chr(13));
    if data = 'F' then wsocket1.SendStr(HexToString(StringReplace(Edit2.Text,' ','',[rfReplaceAll, rfIgnoreCase]))+chr(13));

    if data = Hextostring('00') then wsocket1.SendStr(HexToString(StringReplace('41 58',' ','',[rfReplaceAll, rfIgnoreCase]))+chr(13));

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Wsocket1.SendStr('DUPA');
end;

procedure TForm1.WSocket1SessionAvailable(Sender: TObject; ErrCode: Word);
begin
wsocket1.hsocket:= wsocket1.accept;
end;

procedure TForm1.WSocket1SessionClosed(Sender: TObject; ErrCode: Word);
begin
//PostMessage(Handle, WM_CLOSE_REQUEST, 0, LParam(WSocket1));
PostMessage(Handle, WM_AUTO_START, 0, 0);

end;
end.

 

by: RickJPosted on 2006-04-07 at 04:00:08ID: 16399284

In your download you would have the Delphi\Internet directory.
Open the CliDemo and the SrvDemo. Run them both and check code to see how they are communicating between each other.
This is what you are after??

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...