Einzelnen Beitrag anzeigen

Klaus-B.Schmidt

Registriert seit: 2. Apr 2004
Ort: Braunschweig
65 Beiträge
 
Delphi 2005 Personal
 
#4

Re: idtcpclient dissconnected

  Alt 4. Aug 2004, 15:15
wie versprochen, hier der code:

Server:
Delphi-Quellcode:
procedure TForm1.ServerConnect(AThread: TIdPeerThread);
begin
  //TBXDockablePanel1.Visible:=false;
  TBXLabel1.Caption:=AThread.Connection.LocalName;
  TBXLabel2.Caption:=timetostr(now);
  TBXLAbel3.Caption:=timetostr(now);
  LogBox.Lines.Add(timetostr(now)+' : Cnnection from '+ATHread.Connection.Socket.Localname);
end;

procedure TForm1.ServerExecute(AThread: TIdPeerThread);
var
  CB:TCommBlock;
  stream:TStream;
begin
  Athread.Connection.ReadBuffer(cb,sizeof(cb));
  if cb.Command='GETthen begin
    LogBox.Lines.Add(timetostr(now)+' Recive GET Command :'+CB.Msg);
    Stream := TFileStream.Create(extractfilepath(Application.exename)+'data\'+CB.Msg, fmOpenRead);
    AThread.Connection.OpenWriteBuffer;
    AThread.Connection.WriteStream(Stream);
    AThread.Connection.CloseWriteBuffer;
    Stream.Free;
  end;
end;
client:
Delphi-Quellcode:
//edit2: hier der richtige code:
procedure TForm1.Button1Click(Sender: TObject);
begin
client.Connect(10000);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  CB:TCommBlock;
  AStream:TMemoryStream;
begin
  CB.Command:=edit1.Text;
  cb.Msg:=edit2.Text;
  AStream:=TMemoryStream.Create;
  try
    Client.WriteBuffer(cb,sizeof(cb));

    Client.ReadStream(AStream,-1,true);
    AStream.Seek(0,sofrombeginning);
    SynEdit1.Lines.LoadFromStream(AStream);
  finally
    AStream.Free;
  end;
end;

end.
und der type TCommBlock :
Delphi-Quellcode:
unit GlobalUnit;

interface

type
  TCommBlock = record // the Communication Block used in both parts (Server+Client)
                 Command,
                 Msg:string[100]; // the message itself
              end;

implementation

end.
Karsten
  Mit Zitat antworten Zitat