Hallo,
Ich habe mir ein kleines Prog geschrieben und zwar soll der server auf anforderung an den clienten ein bild schicken! Sitze jetzt schon Tagelang dadran ich kriegs nicht hin! Weiss jemand wo mein Fehler ist hier der Code vom Server und vom CLienten!
---SERVERPROGRAMM---
Delphi-Quellcode:
type
TForm1 = class(TForm)
ServerSocket1: TServerSocket;
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
myString : String;
buff : array[0..MAX_COMPUTERNAME_LENGTH] of char;
nsize : DWORD;
rc : hwnd;
begin
nsize := SizeOf(buff);
myString := Socket.ReceiveText;
Randomize();
if MyString = 'screenshot' then
Socket.SendStream(TFileStream.Create('c:\screen.jpg', fmOpenRead or fmShareDenyWrite))
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
serversocket1.Active:=true;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
serversocket1.Close;
end;
end.
---CLIENT PROGRAMM---
type
TForm1 = class(TForm)
Edit1: TEdit;
Button5: TButton;
Button8: TButton;
ClientSocket1: TClientSocket;
procedure Button5Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Connecting(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FStream: TStream;
implementation
{$R *.dfm}
procedure TForm1.Button5Click(Sender: TObject);
begin
if ClientSocket1.Active = False then
begin
ClientSocket1.Host := Edit1.Text;
ClientSocket1.Port := 1111;
ClientSocket1.Active := True;
Button5.Caption := 'DISCONNECT';
end
else
begin
ClientSocket1.Active := True;
ClientSocket1.Close;
Button5.Caption := 'CONNECT';
end
end;
procedure TForm1.Button8Click(Sender: TObject);
var
iLen: Integer;
Bfr: Pointer;
begin
ClientSocket1.Socket.SendText('screenshot');
iLen := clientsocket1.Socket.ReceiveLength;
GetMem(Bfr, iLen);
try
clientsocket1.Socket.ReceiveBuf(Bfr^, iLen);
FStream.Write(Bfr^, iLen);
finally
FreeMem(Bfr);
end;
end;
procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
form1.Caption := 'CONNECTED';
end;
procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Form1.Caption := 'NOT CONNECTED';
end;
procedure TForm1.ClientSocket1Connecting(Sender: TObject;
Socket: TCustomWinSocket);
begin
Form1.Caption := 'CONNECTING';
FStream := TFileStream.Create('c:\test.jpg', fmCreate or fmShareDenyWrite);
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
ShowMessage(Socket.ReceiveText);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FStream := nil;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if Assigned(FStream) then
begin
FStream.Free;
FStream := nil;
end;
end;
end.
Wieso klappt das nicht? Ich dreh noch durch das kann doch nicht so schwer sein!
[edit=Sharky]Heute zum x-ten mal Delphi-Tags gesetzt. Mfg, Sharky[/edit]