achso, entschuldigung,
wenn ich auf übertragen klicke passiert nichts außer das sich der opendialog öffnet,
und wenn ich dnan nochmal auf den button klicke kommt "verbundung durch software getrennt" als fehler.
Hier noch der Code, den ich verwende:
Delphi-Quellcode:
var
Form1: TForm1;
sM, rM:TMemoryStream;
Rec: Boolean = false;
rSize: Int64;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
ClientSocket1.Active:=true;
end;
procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Label1.Caption:='connected';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ClientSocket1.Active:=false;
Label1.Caption:='disconnected';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
sM := TMemoryStream.Create;
rM := TMemoryStream.Create;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FreeAndNil(sM);
FreeAndNil(rM);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
sM.LoadFromFile(OpenDialog1.FileName);
ClientSocket1.Socket.SendText(IntToStr(sM.Size));
end;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
rL:integer;
begin
rL:=Socket.ReceiveLength;
If rL=0 then Exit;
If Rec then
begin
Socket.ReceiveBuf(Pointer(Int64(rM.Memory) + rM.Position)^, rL);
rM.Position :=rM.Position + rL;
If rM.Position = rSize then
begin
rM.SaveToFile('C:\Recieve.txt');
Rec := False;
end
end else begin
rM.Size := StrToInt(Socket.ReceiveText);
rM.SetSize(rSize);
rM.Position := 0;
Rec := true;
Socket.SendText('ok');
end;
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
If Socket.ReceiveText = 'ok' then
Socket.SendBuf(sM.Memory^, sM.Size);
end;
end.