Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jan : Re: Open a TCP Socket
| Subject: | Re: Open a TCP Socket |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Thu, 31 Jan 2008 10:05:35 |
"Kim Jensen" <kim@comcasystems.com> wrote in message
news:47a11e86$1@newsgroups.borland.com...
> I'm using the Indy version that came with Delphi 2007. (Indy 10)
Then you are using a very old version and should upgrade.
> According to the instruction I just have to send ASCII strings to
> the controller and I will receive ASCII strings back.
But in what format exactly? What do the instructions actually say?
ReadLn() may or may not be the correct method to do, depending on the actual
format of the strings.
> After using the TIdIOHandlerStack I start getting some result
> but I found that if I try to use ReadLn and there is nothing to
> read the program will hang.
That is what it is supposed to do.
> Is there anyway to check if there is something to read before
> I use ReadLn?
In general, you really shouldn't be using Indy that way. It is designed to
wait for data until it arrives. If you must check for data before reading
it, then call the IOHandler's CheckForDataOnSource() method, and then query
the IOHandler's InputBuffer.Size property afterwards.
> I added TIdTCPClient and TIdIOHandlerStack to the form.
You do not need to use a separate TIdIOHandlerStack. TIdTCPClient creates
one internally for you if you do not assign your own.
> IdTCPClient1.Connect;
> if IdTCPClient1.Connected then
You don't need to call Connected(). Connect() raises an exception if it
fails:
procedure TForm1.Button1Click(Sender: TObject);
begin
IdTCPClient1.Connect;
Button2.Enabled := True;
end;
> IdIOHandlerStack1.WriteLn(EDIT1.Text + #13#10);
WriteLn() already appends a CRLF for you. You do not need to do it
manually:
procedure TForm1.Button2Click(Sender: TObject);
begin
IdTCPClient1.IOHandler.WriteLn(Edit1.Text);
end;
Gambit