Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   No aceptar conexion cliente TServerSocket (https://www.clubdelphi.com/foros/showthread.php?t=53648)

Jose Angel 26-02-2008 15:28:54

No aceptar conexion cliente TServerSocket
 
Me gustaría saber como denegar las conexiones de clientes a un componente TServerSocket.
Muchas gracias.

radixzz 26-02-2008 20:02:28

TClientSocket
 
Pues lo unico que tienes que hacer es hacer una comparación de la ip del cliente dentro del evento OnConnect del TServerSocket

la comparacion seria algo asi:


Código Delphi [-]
if AContext.Connection.Socket.Binding.PeerIP='192.168.1.1' then Begin  {Manda un mensaje de desconexion o simplemente desconectalo} 
End;

es un modo muy manual pero sirve, si quieres tener una especia de blacklist podrias crear una lista de tipo tList y buscar el hilo para desconectarlo usando una funcion como esta:


Código Delphi [-]
Function BuscaHiloporIP(direccionIP:shortstring):integer;
var
  ListaCXN:tList;
  match,i:integer;
Begin
ListaCXN:=ServerSocket.Contexts.LockList;
match:=-1;
Try
  IF ListaCXN.Count>0 Then
  Begin
      For i:=0 to ListaCXN.Count-1 DO Begin
        IF TidContext(ListaCXN.Items[i]).Connection.Socket.Binding.PeerIP=direccionIP Then
        Begin
        match:=i;
        break;
        end else begin
        match:=-1;
        End;
      End;
  End;
Finally
ServerSocket.Contexts.UnlockList;
result:=match;
End;
End;


Un Saludo!


La franja horaria es GMT +2. Ahora son las 04:50:27.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi