procedure TF_main.Timer1Timer(Sender: TObject);
begin
if not ClientSocket1.Active then
begin
clientsocket1.Host:=strseraddr;
ClientSocket1.Active:=true;
ClientSocket1.Socket.Lock;
end
else
begin
ClientSocket1.Socket.SendText(strSockType+','+strIP+','+strSockValue+',');
Timer1.Enabled:=false;
end;
end;
procedure TF_main.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
try
if errorcode=0
then
begin
..........
end;
except
....
end;
end;
Specifies whether the client socket reads and writes information asynchronously over the socket connection.
type TClientType = (ctNonBlocking, ctBlocking);
property ClientType: TClientType;
Description
Set ClientType to ctNonBlocking to enable the client socket to respond to asynchronous reading and writing events. When ClientType is ctNonBlocking, execution is not blocked by reading and writing over the socket connection. OnRead or OnWrite events occur when the socket needs to read or write over the connection.
Set ClientType to ctBlocking to force all reading and writing to occur synchronously. It is a good idea to include the client socket object in a thread if the ClientType is ctBlocking, so that I/O does not block all execution within the client application.
When ClientType is ctBlocking, use a TWinSocketStream object for reading and writing. TWinSocketStream prevents the application from hanging indefinitely if a problem occurs while reading or writing. It also can wait for the socket connection to indicate its readiness for reading.
Use a non-blocking socket when the socket needs to synchronize reading and writing with server sockets.