Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   Problema con servidor TCP (https://www.clubdelphi.com/foros/showthread.php?t=53305)

gallipi 18-02-2008 12:44:57

Problema con servidor TCP
 
hola,
estoy haciendo un servidor TCP con componente indy para delphi y en principio me funciona bastente bien.
El problema que tengo es que cuando me llegan muchas peticiones rapidas por parte de un solo cliente al final me lanza un error y el programa deja de ejecutarse " Acces violaton at adress 0000000 ..." y no se a que es devido.
este es el trozo de codigo que se ejecuta cuando me llega una peticion por parte del cliente

Código Delphi [-]
procedure TModuleManager.tcpServerExecute(AThread: TIdPeerThread);
var
  mensaje : string;

begin
  try
   mensaje:=  AThread.Connection.ReadLn; // leer domando que me envian
   if mensaje<> ' ' then
     begin
       mensaje := mensaje + ',Lagun.dll';
       EjecutarTarea(Pchar(mensaje)); // que haga lo que tenga que hacer
     end;
  except
    raise exception.Create('Server');
  end;
end;

gallipi 18-02-2008 17:44:22

supongo que es porque el readln es bloqueante y hasta recibir un mensaje se queda esperando, entonces, si un cliente se desconecta, el hilo esta en el readln y al perder el socket dara el error ese.

La duda que me queda es que es lo que tengo que hacer cuando un cliente se desconecte, si tengo que lieberar el hilo o simplemente tengo que hacer un exit.

procedure TModuleManager.tcpServerExecute(AThread: TIdPeerThread);
begin
try
mensaje := AThread.Connection.ReadLn;
if mezua <> ' ' then
begin
if mensaje = 'fin' then exit; // DUDA, SI EL CLIENTE DESCONECTA SIMPLEMENTE TENGO QUE HACER UN EXIT O TENGO QUE LIBERAR EL HILO??
mensaje:=mensaje + ',Lagun.dll';
Athread.Synchronize(TareaThread);
end;
except
raise exception.Create('Server');
end;
end;


La franja horaria es GMT +2. Ahora son las 19:40:44.

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