TClientSocket

TClientSocket

Post by Team » Sat, 09 Aug 2003 05:30:33



Are you using the socket in blocking or non-blocking mode? If non-blocking,
then you must wait for the socket to actually connect before you send data
over the socket. Setting the Active property returns immediately, the
socket is connected asynchronously, the various operations involved during
connecting are based on windows messages posted to the main message queue.
You will have to either wait for the OnConnect event to trigger:

FCmd: String;

procedure TForm1.sendEth(string cmd);
begin
FCmd := cmd;
ClientSocket1.Active := True;
end;

procedure TForm1.ClientSocket1Connect(Socket: TCustomWinSocket);
begin
Socket.Send(FCmd);
end;

Or else call TApplication::ProcessMessages() until the Active property
reports true:

procedure TForm1.sendEth(string cmd);
begin
ClientSocket1.Active := True;
repeat Application.ProcessMessages until ClientSocket1.Active;
ClientSocket1.Socket.Send(cmd);
end;


Gambit
 
 
 

TClientSocket

Post by Jack Maso » Wed, 05 Nov 2003 07:28:02

What is the Delphi 7 replacment for Delphi 6's TClientSocket?

 
 
 

TClientSocket

Post by Team » Fri, 07 Nov 2003 19:59:51


As far as I know, TClientSocket exists in Delphi 7 as well.


Gambit
 
 
 

TClientSocket

Post by Jaso » Mon, 10 Nov 2003 13:17:52


Ahh a little example to explain....

{/*------------------| SendString Different object
|-----------------------------------------------------------------------------*
| Description:
| ~~~~~~~~~~~
| Connects to a socket and sends your string. Use the Delphi Default
| TCPClient Object
|
| Parameters:
| ~~~~~~~~~~~
| Host : Computer or IP to connect to
| Port : Port number to connect
| YourString : Data to send. \r\n is sent automatically
| TimeOut : Milliseconds to wait before returning
| TCPClient1 : Object to use for connection
|
| Return Codes:
| ~~~~~~~~~~~~
| TStringList : Skips blank returns (\r\n etc....)
\*--------------------------------------------------------------------------------------------------
----------------------------*/}
function SendString(Host: string; Port: string; YourString: string; TimeOut: Integer; TCPClient1:
TTCPClient): TStringList;
var
s: string;
ReturnList: TStringList;
begin
ReturnList := TStringList.Create;

TCPClient1.Close;
TCPClient1.RemoteHost := Host;
TCPClient1.RemotePort := Port;
TCPClient1.Active := true;
TCPClient1.Open;

TcpClient1.Sendln(YourString);
TcpClient1.Sendln('\r\n');
while (true) do
begin
if (not TCPClient1.WaitForData(TimeOut)) then
break;
s := TCPClient1.Receiveln(#10);
s := Trim(s);
if s <> '' then
ReturnList.Add(s);
end;

TcpClient1.Close;
TcpClient1.Active := FALSE;

RESULT := ReturnList;

end;
 
 
 

TClientSocket

Post by Team » Mon, 10 Nov 2003 14:17:58


You're referring to the TTcpClient component in CLX. That has nothing to do
with the TClientSocket component in VCL.


Gambit