Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Jun : Re: Help to read from port 30003 using indy

www.cryer.info
Managed Newsgroup Archive

Re: Help to read from port 30003 using indy

Subject:Re: Help to read from port 30003 using indy
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Fri, 16 Jun 2006 10:06:33

"dogo" <dogo_daz@removeit_msn.com> wrote in message
news:4492b85e@newsgroups.borland.com...

> How do I go about doing this

Using a TIdTCPClient, simply set the Port to 30003 (and the Host
accordingly, of course), call Connect(), and then call ReadLn()
periodically, such as in a timer or a thread (a thread would be better).

> I had a go using TClientSocket

Why?

> which does work but some of the data goes missing

That is because your code is incomplete.  You are not taking into account
that data can be split up between multiple OnRead events.  You are assuming
that the data is always complete each time the event is triggered, and that
is simply not how TCP works.  Assuming you are using the TClientSocket in
non-blocking mode, then you need to buffer all incoming data, and then run
through the buffer to see if you have any complete lines available in the
buffer each time.  If not, then leave the current data in the buffer and
wait for the next even to put more data into the buffer.

Please go to http://www.deja.com and search through the newsgroup archives.
Sample code for handling all of that has been posted many times before.

>   s := socket.ReceiveText;
>   Memo1.Lines.Add(Socket.ReceiveText);

That won't work.  The first call to ReceiveText() will have read everything
that was available on the socket, so the second read will always return an
empty string.

>   a := s;
>   setlength(s, 3);
>   if s = 'AIR' then
>   begin
>    // Label1.Caption := a;
>     plane := TstringList.Create;

>     plane.Delimiter := ',';
>     plane.DelimitedText := a;

Use the CommaText property instead.

>    // label3.Caption := plane.Strings[4];
>     if plane.Strings[4] = Edit1.Text then
>     begin
>       Memo2.Lines.Add('Found ' + plane.Strings[4] + ' On ' +
> Plane.Strings[6] +
>         ' at ' + Plane.Strings[7]);
>     End;

You are not validating that there are actually 8 or more items in the
TStringList before accessing them.


Gambit

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive