Einzelnen Beitrag anzeigen

Mayday171

Registriert seit: 19. Apr 2006
40 Beiträge
 
#1

Probleme mit SendBuf und ReceiveBuf

  Alt 13. Jun 2007, 15:20
Hallo Leute,

Versuche mit SendBuf in einer ClientApplikation Daten einer Shell Komponente an eine ServerApplikation zu senden.
Mache das ganze mit sendBuf und receiveBuf...

Irgendwie funktioniert das ganze nicht. Es kommt nix an. Er sendet zwar aber auf der anderen Seite kommt nix !!

Bitte Helf mir

CLIENT

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Sockets, ShellCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    clientstatus: TEdit;
    shelltreeview: TShellTreeView;
    TcpClient1: TTcpClient;
    procedure TcpClient1Connect(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TcpClient1Send(Sender: TObject; Buf: PAnsiChar;
      var DataLen: Integer);
    procedure TcpClient1Error(Sender: TObject; SocketError: Integer);
    procedure TcpClient1Disconnect(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  test: TTreeNodes;


implementation

{$R *.dfm}

procedure TForm1.TcpClient1Connect(Sender: TObject);
begin
  test:= shelltreeview.Items;
  clientstatus.Text:='Client verbunden';


      tcpclient1.SendBuf(test,sizeof(test));

end;


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  tcpclient1.Close;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     tcpclient1.Connect;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  tcpclient1.Connect;
  tcpclient1.Open;
end;

procedure TForm1.TcpClient1Send(Sender: TObject; Buf: PAnsiChar;
  var DataLen: Integer);
begin
  clientstatus.Text:='sendet';
end;

procedure TForm1.TcpClient1Error(Sender: TObject; SocketError: Integer);
begin
  clientstatus.Text:='Fehler';
end;

procedure TForm1.TcpClient1Disconnect(Sender: TObject);
begin
  clientstatus.Text:='getrennt'
end;

end.

SERVER

Delphi-Quellcode:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Sockets, ShellCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    serverstatus: TEdit;
    treeview: TTreeView;
    TcpServer1: TTcpServer;
    procedure TcpServer1Accept(Sender: TObject;
      ClientSocket: TCustomIpClient);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TcpServer1Listening(Sender: TObject);
    procedure TcpServer1GetThread(Sender: TObject;
      var ClientSocketThread: TClientSocketThread);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  test: TTreeNodes;


implementation

{$R *.dfm}


procedure TForm1.TcpServer1Accept(Sender: TObject;
  ClientSocket: TCustomIpClient);
begin
  serverstatus.Text:='Server verbunden';
  while tcpserver1.WaitForData(4000) do
    begin
      tcpserver1.ReceiveBuf(test,sizeof(test));
      showmessage(test.GetFirstNode.Text);
    end;
  treeview.Items:=test;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  tcpserver1.Close;
end;


procedure TForm1.TcpServer1Listening(Sender: TObject);
begin
  serverstatus.Text:='listening'
end;

procedure TForm1.TcpServer1GetThread(Sender: TObject;
  var ClientSocketThread: TClientSocketThread);
begin
  serverstatus.Text:='getThread';
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  tcpserver1.Open;
end;

end.
  Mit Zitat antworten Zitat