Mon projet est de récuperer des screenshoots et des logs d'un serveur ou plusieurs serveurs.
Etant debutant en Delphi surtout sur la partie reseau (composant Indy) je me suis inspiré d'un explemple (ScreenThief - stealing screen shots over the Network) disponible a l'adresse ci-dessous:
http://delphi.about.com/od/internetintranet/l/aa012004a.htm

J'y ai greffé une partie permettant de recuperer les fichiers logs (enfin un pour l'instant )

Mon probleme se situe dans la partie cliente:
Lors du 1er passage dans la condition "if sCommand = 'TakeLog' then"
tout ce passe bien et le transfert du fichier ce fait correctement.
Mais lors du deuxieme passage le programme "gele" est ne repond a plus aucune commande comme si le stream etait cassé.
Le prog s'arrete a la ligne "TCPClient.OpenWriteBuffer;"
Naturellement le transfert de screenshots ne fonctionnent plus apres le deuxieme appel

Voici le code de la partie cliente:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
procedure TMainFormClient.TimerTimer(Sender: TObject);
var
  FileStream : TFileStream;
  JpegStream : TMemoryStream;
  pic : TBitmap;
  sCommand : string;
begin
  if not TCPClient.Connected then Exit;
 
  Timer.Enabled := False;
 
  TCPClient.WriteLn('CheckMe'); //command handler
  sCommand := TCPClient.ReadLn;
 
 
  begin
    IncomingMessages.Lines.Insert(0,'About to take a log: ' + DateTimeToStr(Now));
    //envoi le fichier de logs
 
    EnterCriticalSection(CritSect);
    //FileStream := TFileStream.Create('C:\LOG.TXT',fmopenwrite);
    FileStream := TFileStream.Create('C:\LOG.TXT',fmOpenRead,fmShareDenyWrite);
    LeaveCriticalSection(CritSect);
        TCPClient.WriteInteger(FileStream.Size);
        TCPClient.OpenWriteBuffer;
        TCPClient.WriteStream(FileStream);
        TCPClient.CloseWriteBuffer;
        FreeAndNil(FileStream);
 
 
    TCPClient.ReadLn;
  end;
 
  if sCommand = 'TakeShot' then
  begin
 
    pic := TBitmap.Create;
    JpegStream := TMemoryStream.Create;
    ScreenShot(0,0,Screen.Width,Screen.Height,pic);
    BMPtoJPGStream(pic, JpegStream);
    pic.FreeImage;
    FreeAndNil(pic);
 
    // copy file stream to write stream
    TCPClient.WriteInteger(JpegStream.Size);
    TCPClient.OpenWriteBuffer;
    TCPClient.WriteStream(JpegStream);
    TCPClient.CloseWriteBuffer;
    FreeAndNil(JpegStream);
 
    //making sure!
    TCPClient.ReadLn;
  end;
 
  Timer.Enabled := True;
end;
Le code de la partie serveur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
procedure TMainFormServer.TCPServerExecute(AThread: TIdPeerThread);
var
  Client : PClient;
  Command : string;
  Size : integer;
  PicturePathName : string;
  ftmpStream : TFileStream;
 
begin
 
  if not AThread.Terminated and AThread.Connection.Connected then
  begin
    Client := PClient(AThread.Data);
    Client.LastAction := Now;
 
    Command := AThread.Connection.ReadLn;
    if Command = 'CheckMe' then
    begin
      if client.TakeLog = True then
      begin
         Client.TakeLog := False;
         AThread.Connection.WriteLn('TakeLog');
         PicturePathName := ExtractFileDir(ParamStr(0)) + '\' + Client.HostName + '_Log' + inttostr(i) + '.txt';
         i := i + 1;
        if FileExists (PicturePathName) then DeleteFile(PicturePathName);
        ftmpStream := TFileStream.Create(PicturePathName,fmCreate);
        Size := AThread.Connection.ReadInteger;
        AThread.Connection.ReadStream(fTmpStream,Size,False);
        FreeAndNil(fTmpStream);
 
        AThread.Connection.WriteLn('Take Log DONE');
 
        ClientsListBoxClick(nil);
 
      end;
      if Client.TakeShot = True then
      begin
        Client.TakeShot := False;
 
        AThread.Connection.WriteLn('TakeShot');
 
        PicturePathName := ExtractFileDir(ParamStr(0)) + '\' + Client.HostName + '_Screen.JPG';
 
        if FileExists (PicturePathName) then DeleteFile(PicturePathName);
        ftmpStream := TFileStream.Create(PicturePathName,fmCreate);
        Size := AThread.Connection.ReadInteger;
        AThread.Connection.ReadStream(fTmpStream,Size,False);
        FreeAndNil(fTmpStream);
 
        AThread.Connection.WriteLn('DONE');
 
        RefreshImage(Client.HostName, PicturePathName);
        ClientsListBoxClick(nil);
      end
      else
        AThread.Connection.WriteLn('DONE');
    end;
  end;
end;
Quelqu'un a-t-il une idée ou voit-il une erreur dans le code ?
Merci d'avance