Hello! I did a lot of things with TClientSocket and
TServer socket. That is sending text, records, files in both way. Then I want to do the same thing with Indy - TIdTCPServer and TIdTCPClient. And here I'm puzzled. I stuck with sending raw binary files in direction Client to Server.
My idea was when client connects to server it sends a file and server saves it in default folder.
This is the code:
Client side:
procedure TFormClientMain.Button1Click(Sender: TObject);
var
FStream: TFileStream;
begin
if OpenDialog1.Execute then
begin
FStream:= TFileStream.Create(OpenDialog1.FileName, fmOpenRead);
with MyIdTCPClient1 do
begin
Connect;
WriteStream(FStream);
Disconnect;
end; { end of MyIdTCPClient1 }
FStream.Free;
end; { end of OpenDialog1.Execute }
end;
Server side:
On form create I activate the server
procedure TFormMyServerMainWindow.MyIdTCPServerExecute(AThread: TIdPeerThread);
var
FStream: TFileStream;
begin
with AThread.Connection do
begin
memo1.Lines.Add('Connected');
FStream:= TFileStream.Create('C:\tempppp', fmOpenWrite or fmCreate);
ReadStream(FStream,-1,true);
Disconnect;
FStream.Free;
memo1.Lines.Add('Disconnected');
end; { end of AThread.Connection }
end; { end of MyIdTCPServerExecute }
Port is the same like ip address. I'm using Delphi 6 enterprise (sp2) on winxp.
What am I doing wrong? It nothing happens (actually it creates a file tempppp but it is empty.
And it writes 'Connected' in memo1, but it does not write 'Disconnected').
I'm hoping that someone could help me...
TServer socket. That is sending text, records, files in both way. Then I want to do the same thing with Indy - TIdTCPServer and TIdTCPClient. And here I'm puzzled. I stuck with sending raw binary files in direction Client to Server.
My idea was when client connects to server it sends a file and server saves it in default folder.
This is the code:
Client side:
procedure TFormClientMain.Button1Click(Sender: TObject);
var
FStream: TFileStream;
begin
if OpenDialog1.Execute then
begin
FStream:= TFileStream.Create(OpenDialog1.FileName, fmOpenRead);
with MyIdTCPClient1 do
begin
Connect;
WriteStream(FStream);
Disconnect;
end; { end of MyIdTCPClient1 }
FStream.Free;
end; { end of OpenDialog1.Execute }
end;
Server side:
On form create I activate the server
procedure TFormMyServerMainWindow.MyIdTCPServerExecute(AThread: TIdPeerThread);
var
FStream: TFileStream;
begin
with AThread.Connection do
begin
memo1.Lines.Add('Connected');
FStream:= TFileStream.Create('C:\tempppp', fmOpenWrite or fmCreate);
ReadStream(FStream,-1,true);
Disconnect;
FStream.Free;
memo1.Lines.Add('Disconnected');
end; { end of AThread.Connection }
end; { end of MyIdTCPServerExecute }
Port is the same like ip address. I'm using Delphi 6 enterprise (sp2) on winxp.
What am I doing wrong? It nothing happens (actually it creates a file tempppp but it is empty.
And it writes 'Connected' in memo1, but it does not write 'Disconnected').
I'm hoping that someone could help me...