Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Sep : Converting From TClientSocket
| Subject: | Converting From TClientSocket |
| Posted by: | "Jack Mason" (jackmas..@mindspring.com) |
| Date: | Fri, 31 Aug 2007 23:11:43 |
We need to convert from TClientSocket to something that is supported
under D7 and D2006. We have the TClientSocket code working fine, but
TClientSocket keeps disappearing when we need to make a modification.
Several people have suggested Indy TIdTCPClient as a replacement. We
don't want/need a thread. 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.
We tried the simple approach, ie:
Socket: TIdTCPClient;
Request, Response: string;
...
procedure TForm1.Start;
begin
Request := Request_Data;
Socket.Host := Host;
Socket.Port := Port;
Socket.Connect(-1);
end;
procedure TForm1.SocketConnected(Sender: TObject);
var Temp_Str: string;
Byte_Count: integer;
begin
Socket.Write(Request);
Response := Socket.ReadString(34);
Temp_Str := Copy(Response, 29, 5);
Byte_Count := StrToInt(Temp_Str);
Response := Socket.ReadString(Byte_Count - 34);
Socket.DisconnectSocket;
end;
but get an immediate "read timeout" error when the read occurs. I have
tried to find an example of a simple socket client in the Indy demos
but have not seen one. Is it just that we are doing the read
incorrectly, or is the write not occurring?