Autor Beitrag
Klaus-B.Schmidt
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 70

WinXP u. Win2000
D6 Enterprise
BeitragVerfasst: Di 03.08.04 13:58 
hi leute, ich habe ein programm, welches ich mit dem gleichen programm auf einem anderen PC verbinden lassen möchte (netzwerk, inetrnet), und alle handlungen(treeview anzeigen,datei editieren, ...) mit den dateien des anderen programmes lädt/edittiert/..., dazu muß man sich aber auch erst auf dem programm einloggen.

Programmdatenstruktur:
Programmverzeichnis\data\ << dort leigen alle daten, einstellungen etc.

zu dem wärs gut, wenn das programm, welches eine eigehende verbindung bekommt eine sicherung der alten daten erstellt, um sie evtl. wiederherzustellen.

MfG
Klaus
Klaus-B.Schmidt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 70

WinXP u. Win2000
D6 Enterprise
BeitragVerfasst: Di 03.08.04 20:20 
ich hab shcon eine möglichkeit gefunden dies zu realisieren (mit hilfe der indy demos) :

Server:
ausblenden volle Höhe Delphi-Quelltext
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:
61:
62:
implementation

uses GlobalUnit;

{$R *.DFM}

procedure TServerFrmMain.ServerConnect(AThread: TIdPeerThread);
begin
 Label1.Caption:=AThread.Connection.LocalName;
 Label2.Caption:=timetostr(Now);
 Label3.Caption:=timetostr(now);

 Protocol.Lines.Add(TimeToStr(Time)+' Connection from "'+AThread.Connection.LocalName+'"');
end;

procedure TServerFrmMain.ServerExecute(AThread: TIdPeerThread);
var
  CommBlock,CB: TCommBlock;
  i: Integer;
  PStream,stream:TStream;
begin
  if not AThread.Terminated and AThread.Connection.Connected then
  begin
    AThread.Connection.ReadBuffer (CommBlock, SizeOf (CommBlock));
    Label3.Caption:=timetostr(Now);
    if commblock.Command='GET' then begin
      Protocol.Lines.Add(timetostr(now)+' Recive GET Command :'+commblock.Msg);
      Stream := TFileStream.Create(extractfilepath(Application.exename)+'data\'+commblock.Msg, fmOpenRead);
      AThread.Connection.OpenWriteBuffer;
      AThread.Connection.WriteStream(Stream);
      AThread.Connection.CloseWriteBuffer;
      Stream.Free;
    end;
    if commblock.Command='POST' then
     Protocol.Lines.Add(timetostr(now)+' Recive POST Command :'+commblock.Msg);
      Stream := TFileStream.Create(extractfilepath(Application.exename)+'data\'+commblock.Msg, fmCreate);
      AThread.Connection.ReadBuffer(PStream, SizeOf(PStream));
      Stream.WriteBuffer(PStream,SizeOf(PStream));
      Stream.Free;

    end;
    end;

procedure TServerFrmMain.ServerDisconnect(AThread: TIdPeerThread);
begin
  Protocol.Lines.Add (TimeToStr(Time)+' Disconnect from "'+AThread.Connection.LocalName+'"');
  Label1.Caption:='';
  Label2.Caption:='';
  LAbel3.caption:='';
end;

procedure TServerFrmMain.FormCreate(Sender: TObject);
begin
Server.Active:=true;
end;

procedure TServerFrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Server.Active := False;
end;

end.


Client:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TClientFrmMain.ButtonSendClick(Sender: TObject);
var
  CommBlock : TCommBlock;
  str:TStream;
begin
  CommBlock.Command      := EditCommand.Text;         // assign the data
  CommBlock.Msg          := EditMessage.Text;
  TCPClient.WriteBuffer (CommBlock, SizeOf (CommBlock));

  TCPClient.ReadStream(str);
  str.Seek(0,soFromBeginning);
  SynEdit1.Lines.LoadFromStream(str);
  end;

procedure TClientFrmMain.FormCreate(Sender: TObject);
begin
  tcpclient.Connect(10000);
end;


er sendet die Get bzw. Post anweisungen zum server, aber er bekommt nichts zurück, entweder hängt das prog(mit antifreez) oder es kommt die meldung die verbindung wurde erfolgreich geschlossen.

vielleicht kann mir jetzt jmnd. weiterhelfen ?

MfG
Klaus