Ver Mensaje Individual
  #17  
Antiguo 09-07-2010
Avatar de richy08
richy08 richy08 is offline
Miembro
 
Registrado: may 2007
Ubicación: Bucerias, Nayarit Mexico
Posts: 529
Reputación: 17
richy08 Va por buen camino
hola manuc ya logre que funcione la aplicacion no la he terminado primero me gustaria preguntarte algo, ahora lo unico que hace es que cuando el cliente envia la peticion de conexion le regresa la cadena diciendole que le proceso se hizo, creo que con esto bastara ya despues le agregare mas campos que seran mis variables al record "TCommBlock", este es el codigo que uso en el cliente


//clientes
Código Delphi [-]
procedure TClientHandleThread.HandleInput;
begin
  if CB.Command = 'MESSAGE' then
     Frm_Posgue.IncomingMessages.Lines.Add (CB.MyUserName + ': ' + CB.Msg)
  else
  if CB.Command = 'DIALOG' then
    MessageDlg ('"'+CB.MyUserName+'" sends you this message:'+#13+CB.Msg, mtInformation, [mbOk], 0)
  else  // unknown command
    MessageDlg('Unknown command "'+CB.Command+'" containing this message:'+#13+CB.Msg, mtError, [mbOk], 0);
end;

procedure TClientHandleThread.Execute;
begin
  while not Terminated do
  begin
    if not Frm_Posgue.Client.Connected then
      Terminate
    else
    try
      Frm_Posgue.Client.ReadBuffer(CB, SizeOf (CB));
      Synchronize(HandleInput);
    except
    end;
  end;
end;

  CBClientActive.Checked:=true;
      if CBClientActive.Checked then
      begin
        try
           Client.Connect(10000);  // in Indy < 8.1 leave the parameter away
           ClientHandleThread := TClientHandleThread.Create(True);
           ClientHandleThread.FreeOnTerminate:=True;
           ClientHandleThread.Resume;
        except
            on E: Exception do MessageDlg ('Error while connecting:'+#13+E.Message, mtError, [mbOk], 0);
        end;
      end
      else
      begin
       ClientHandleThread.Terminate;
       Client.Disconnect;
      end;

    CommBlock.Command      := '';//EditCommand.Text;         //     assign the data
    CommBlock.MyUserName   := Client.LocalName;
    CommBlock.Msg          := 'hola';//EditMessage.Text;
    CommBlock.ReceiverName := 'Desarrollo-lap';//EditRecipient.Text;

    Client.WriteBuffer (CommBlock, SizeOf (CommBlock), true);

la pregunta aqui es en que momento desconecto la conexion ya que la mayoria de los procesos de las interfaces se llevan en esta pantalla al ir presionando botones segun cambie de estado la reservacion.


//Server
Código Delphi [-]
procedure TFrm_Interfaces.CBServerActiveClick(Sender: TObject);
begin
  Server.Active := CBServerActive.Checked;
end;

procedure TFrm_Interfaces.ServerConnect(AThread: TIdPeerThread);
var
  NewClient: PClient;
begin
GetMem(NewClient, SizeOf(TClient));

  NewClient.DNS         := AThread.Connection.LocalName;
  NewClient.Connected   := Now;
  NewClient.LastAction  := NewClient.Connected;
  NewClient.Thread      :=AThread;

  AThread.Data:=TObject(NewClient);

  try
    Clients.LockList.Add(NewClient);
  finally
    Clients.UnlockList;
  end;

  Protocol.Lines.Add(TimeToStr(Time)+' Connection from "'+NewClient.DNS+'"');
end;

procedure TFrm_Interfaces.ServerExecute(AThread: TIdPeerThread);
var
  ActClient, RecClient: PClient;                                                                              
  CommBlock, NewCommBlock: TCommBlock;
  RecThread: TIdPeerThread;
  i: Integer;
begin
  if not AThread.Terminated and AThread.Connection.Connected then
  begin
    AThread.Connection.ReadBuffer (CommBlock, SizeOf (CommBlock));
    ActClient := PClient(AThread.Data);
    ActClient.LastAction := Now;  // update the time of last action
     // unknown command given
      Protocol.Lines.Add (TimeToStr(Time)+' !! "'+CommBlock.MyUserName+'": '+CommBlock.Command);
      NewCommBlock.Command := 'DIALOG';       // the message should popup on the client's screen
      NewCommBlock.MyUserName := '[Server]';  // the server's username
      NewCommBlock.Msg := 'The process was done  "'+CommBlock.Command+'"';  // the message to show
      NewCommBlock.ReceiverName := '[return-to-sender]'; // unnecessary
//****************************************************
//codigo de los procesos a ejecutar "segun yo" 
//****************************************************
      AThread.Connection.WriteBuffer (NewCommBlock, SizeOf (NewCommBlock), true);  // and there it goes...
    //end;
  end;
end;

procedure TFrm_Interfaces.ServerDisconnect(AThread: TIdPeerThread);
var
 ActClient: PClient;
begin
  ActClient := PClient(AThread.Data);
  Protocol.Lines.Add (TimeToStr(Time)+' Disconnect from "'+ActClient^.DNS+'"');
  try
    Clients.LockList.Remove(ActClient);
  finally
    Clients.UnlockList;
  end;
  FreeMem(ActClient);
  AThread.Data := nil;
end;


procedure TFrm_Interfaces.FormCreate(Sender: TObject);
begin
  Clients := TThreadList.Create;
end;

procedure TFrm_Interfaces.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Server.Active := False;
  Clients.Free;
end;
entre estas etiquetas creo que debe de ir el codigo de los procesos ver arriba en el codigo del server
//****************************************************
//codigo de los procesos a ejecutar "segun yo"
//****************************************************
la pregunta aqui es que pasa si dos estaciones abren esta pantalla las dos trabajando sobre diferente records y por asares del destino mientras los querys estan haciendo los procesos de la peticion de una maquina, que pasa si otra manda llamar al mismo proceso lso querys seguiran ejecutando la peticion de la otra maquina y esperaran a que terminen para comenzar con la nueva transaccion

gracias.
Responder Con Cita