Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Sep : Re: Converting From TClientSocket
| Subject: | Re: Converting From TClientSocket |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Mon, 3 Sep 2007 17:19:28 |
"Jack Mason" <jackmason@mindspring.com> wrote in message
news:46d8d870@newsgroups.borland.com...
> We need to convert from TClientSocket to something that
> is supported under D7 and D2006.
TClientSocket is still available in those versions. It is simply not
installed by default. You can install the dclsocket... package to install
TClientSocket and TServerSocket into the Component Palette.
> Several people have suggested Indy TIdTCPClient as a
> replacement. We don't want/need a thread.
Then Indy is probably not the right choice for you. There are other
third-party socket components available, such as ICS and Synapse, which can
be used asynchronously.
> We need to 1) connect, 2) send a 50 byte request, and read
> a 34 byte header which provides a byte count, and then we
> read "byte count" worth of data and close the connection.
Indy can handle that just fine, as long as you don't mind blocking the
calling thread until the requested data has been received in full.
> We tried the simple approach, ie:
<snip>
> but get an immediate "read timeout" error when the read occurs.
Does the byte count inside the received header include the header's size as
well as the data size? Your code assumes that it does, but I am guessing
that it does not. If it does not, then you are trying to read too many
bytes, which would cause a timeout error (hich can only happen if you had
changed the ReadTimeut property, since it is set to infinite waiting by
default).
Try this:
procedure TForm1.Start;
var
Byte_Count: Integer;
begin
Socket.Host := Host;
Socket.Port := Port;
Socket.Connect(5000);
try
Socket.Write(Request_Data);
Response := Socket.ReadString(34);
Byte_Count := StrToInt(Copy(Response, 29, 5));
Response := Socket.ReadString(Byte_Count);
finally
Socket.Disconnect;
end;
end;
Gambit