Monitor service with Borland Socket Server

2

I'm developing a three-tiered application in the , using the TSockecConnection component.

Is it possible to monitor connections, identify IP of connected users, as well as knock down some users?

    
asked by anonymous 02.04.2014 / 19:39

1 answer

3

Here is an example of how to perform connection control:

To record which users are connected, you need to use the ClientConnect event of the server socket and add the client to some object, list, or dataset

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
  AdicionaClienteConectado(Socket.RemoteAddress, Socket.RemotePort); 
end;

Likewise, you use the onCLientDisconect event to remove disconnected users from this list

procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  RemoveClienteConectado(Socket.RemoteAddress, Socket.RemotePort); 
end;

And when you want to knock down a user, you just force the disconnection of the user using the information that was used to keep the user's data connected and close the connection

procedure TForm1.DerrubarCliente(const EndCliente: string;
  const PortaCliente: Integer);
var
  I: Integer;
begin
  for I := 0 to ServerSocket1.Socket.ActiveConnections - 1 do
  begin
    if (ServerSocket1.Socket.Connections[I].RemoteAddress = EndCliente) and
      (ServerSocket1.Socket.Connections[I].RemotePort = PortaCliente) then
      ServerSocket1.Socket.Connections[I].Close;
  end;
end;
    
15.04.2014 / 20:20