Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Nov : Re: tidTCPClient/Server - problem transfering data.
| Subject: | Re: tidTCPClient/Server - problem transfering data. |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Fri, 23 Nov 2007 11:14:52 |
"Arvid Haugen" <Arvid@elis.no> wrote in message
news:4746a6fc@newsgroups.borland.com...
> I want to make a code that in case I do not get a correct response
> to my send command I will clear whatever is in the input buffer.
There is no easy way to do that. That is not how sockets are designed to
work. You can clear the InputBuffer itself easy enough (it has a Clear()
method), but you can't erase any unread data that may still be pending on
the socket. You would have to continuously read from the socket until there
is no more data to read. And even then, if the connection is slow, it can
be tricky to determine when the data has ended versus when a timeout has
occured instead. The best thing to do is to simply not send anything at all
when you send an error response back. And format your responses in such a
way that the client always knows exactly how much to read for each
responses, even if it is going to discard the content afterwards.
> In case the response from the server is som non-numeric data
> the "SendCmd" will throw an exception.
Then you are not sending the correct data to begin with. SendCmd() is
designed for RFC-compliant responses, which have very rigid designs. If
your responses are formatted correctly, then SendCmd() will read the full
responses data before raising an exception on a reply code that does not
match the specified acceptable code(s).
> I know that the code below work
Not necessarily. It depends on how many data has been read into the
InputBuffer, and how much remains on the socket.
> but is this the correct way to do this
Of course not. That is a dirty hack, and an incomplete one at that.
Gambit
none