Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jan : Re: Open a TCP Socket
| Subject: | Re: Open a TCP Socket |
| Posted by: | "Kim Jensen" (k..@comcasystems.com) |
| Date: | Wed, 30 Jan 2008 20:04:07 |
I'm using the Indy version that came with Delphi 2007. (Indy 10)
According to the instruction I just have to send ASCII strings to the
controller and I will receive ASCII strings back.
I can use Windows telnet, after it connects I get a : if I send a wrong
command I get a ?
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.
Sometimes the controller does not response and sometimes I get four lines.
Is there anyway to check if there is something to read before I use ReadLn?
Here is what I did:
I added TIdTCPClient and TIdIOHandlerStack to the form.
procedure TForm1.Button1Click(Sender: TObject);
begin
IdTCPClient1.Connect;
if IdTCPClient1.Connected then
begin
Button2.Enabled := True;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
IdIOHandlerStack1.WriteLn(EDIT1.Text + #13#10);
end;
Thanks,
Kim
> What version of Indy are you using? The methods I mentioned earlier are
> declared in TIdTCPConnection (which TIdTCPClient derives from) in Indy 9
> and earlier, and in TIdIOHandler in Indy 10.
>
>> I noticed a Property called IOHandel do I need to add TIdIOHandlerStream?
>
> No. TIdTCPClient.Connect() will initialize the IOHandler property
> automatically if it is not already assigned. Even if you want to assign
> it yourself (which is certainly allowed), TIdIOHandlerStream would be the
> wrong component to use. For TCP support, you would have to use
> TIdIOHandlerSocket (Indy 9 and earlier) or TIdIOHandlerStack (Indy 10)
> instead.
>
>> The controller should respons with ? if I send a wrong command.
>
> But in what format exactly? What is the actual protocol structure that
> you are trying to implement?
>
>
> Gambit