Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 08-09-2006
Edgtho Edgtho is offline
Miembro
 
Registrado: abr 2006
Posts: 47
Poder: 0
Edgtho Va por buen camino
Detectar Socket Desconectado

Buenas, estoy con algo que me tiene de cabeza. Estoy probando comunicaciones entre sockets, digamos que tengo un servidor y un cliente. El cliente se conecta, y perfecto sale como que se ha conectado. Ahora la clave es que me interesa saber como detectar si por alguna razon el cliente se ha desconectado a lo bestia (reseteo del ordenador o cierre a lo bestia).

El codigo del servidor es este
Código:
procedure TForm1.FormCreate(Sender: TObject);
begin
  { Initalize our clients list }
  Clients := TList.Create;
end;

procedure TForm1.IdTCPServerConnect(AThread: TIdPeerThread);
var
  Client : TSimpleClient;
begin
  //Se crea un cliente especifico a esta conexion
  Client := TSimpleClient.Create;

  Client.RemoteIP := AThread.Connection.Socket.Binding.PeerIP;  // IP de conexion
  Client.DNS  := AThread.Connection.LocalName;                  // Nombre local
  Client.Name := 'Log';                                         // Nombre asignado
  Client.ListLink := Contador;                   // Indice del contador

  // Punteros de identificacion del hilo de conexion

  Client.Thread := AThread;
  AThread.Data := Client;
  Athread.Connection.ASCIIFilter := False;
  Clients.Add(Client);

  mLog.Lines.Add('Conexion de ' + client.Name + '-' + client.RemoteIP);
DateToStr(Date) + ';' + TimeToStr(Time));
end;

procedure TForm1.IdTCPServerDisconnect(AThread: TIdPeerThread);
var
  Client : TSimpleClient;
  nombre: string;
begin
  // Identifico el hilo
  Client := Pointer(AThread.Data);

  mLog.Lines.Add('Desconexion de ' + client.Name + '-' + client.RemoteIP);
  // Elimino el hilo de los registros
  Clients.Delete(Client.ListLink);

  // Liberacion de recursos
  Client.Free;
  AThread.Data := nil;
end;


procedure TForm1.IdTCPServerExecute(AThread: TIdPeerThread);
var
  Client : TSimpleClient;
begin
// Identifico el hilo
  Client := Pointer(AThread.Data);

end;
Y estoy intentando detectar si el cliente se ha desconectado mediante este codigo
Código:
var
  List: TList;
  I: Integer;
begin

  List := IdTCPServer.Threads.LockList;
  try
    Application.ProcessMessages;
    for I := 0 to List.Count - 1 do
    begin
      try
//        TIdPeerThread(List.Items[i]).Connection.CheckForDisconnect;
        TIdPeerThread(List.Items[i]).Connection.CheckForDisconnect(True,False);
        TIdPeerThread(List.Items[i]).Connection.WriteLn('algo');
//        TIdPeerThread(List.Items[i]).Connection.CheckForDisconnect(False,True);
        if TIdPeerThread(List.Items[i]).connection.Connected then
        begin
            showmessage('hola');
        end;
      except
            TIdPeerThread(List.Items[i]).Connection.Disconnect;
            Sleep(1000);
      end;
    end;
  finally
    IdTCPServer.Threads.UnlockList;
  end;
Como veis he probado con varias combinaciones de checkfordisconnect, pero nada. Aunque aunque apague el router me sigue dando como conectado (en mi caso el mensaje hola) ¿Alguien me puede echar un cable?
__________________
Dios es real a menos que sea declarado entero
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
NMFTP :Error 10038 Socket operation on non socket judit Internet 2 25-05-2006 09:06:33
como quitar el mensaje "cable de red está desconectado" RONPABLO Windows 2 17-11-2005 23:26:42
Conjunto de datos desconectado sin TClientDataset Rufus Conexión con bases de datos 0 13-04-2005 09:48:35
Detectar desconexion de socket CHiCoLiTa Internet 1 19-07-2004 17:41:29
Socket ID Silver Internet 3 02-09-2003 22:57:46


La franja horaria es GMT +2. Ahora son las 03:21:59.


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
Copyright 1996-2007 Club Delphi