Monitor Service with Borland Socket Server

Asked

Viewed 1,315 times

2

I’m developing a three-layer application on , using the component TSockecConnection.

It is possible to monitor the connections, identify the IP of connected users as well as taking down some user?

  • The answer below has solved your problem?

1 answer

3

Below is an example of how to control connections:

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

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

Similarly, you use the onCLientDisconect event to remove users who log out from this list

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

And when you want to take down a user, just force the disconnection using the information that was used to keep the user 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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.