 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
joke Guest
|
Posted: Sat Jan 31, 2004 2:52 am Post subject: Non-blocking mode memory load |
|
|
I'm using non-blocking for to file transfers by TClientSocket/TServerSocket.
Everything is fine but when i'm sending-receiving files between the
computers in the same network(i mean localhost or local lan) so much memory
load occurs and my application is working so slowly. I know that it's
because of my application's main process and file receive-send opearations
is working in the same thread. Can you suggest me any smooth way for to fix
it ?
Cheers,
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Jan 31, 2004 3:53 am Post subject: Re: Non-blocking mode memory load |
|
|
"joke" <noone (AT) noone (DOT) com> wrote
| Quote: | Can you suggest me any smooth way for to fix it ?
|
Switch to blocking sockets and do the transfers in separate threads from the
main one.
Gambit
|
|
| Back to top |
|
 |
joke Guest
|
Posted: Sun Feb 01, 2004 4:06 pm Post subject: Re: Non-blocking mode memory load |
|
|
isn't there any way with non-blocking more ?
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote
| Quote: |
"joke" <noone (AT) noone (DOT) com> wrote in message
news:401b186b (AT) newsgroups (DOT) borland.com...
Can you suggest me any smooth way for to fix it ?
Switch to blocking sockets and do the transfers in separate threads from
the
main one.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Feb 02, 2004 4:54 am Post subject: Re: Non-blocking mode memory load |
|
|
"joke" <noone (AT) noone (DOT) com> wrote
| Quote: | isn't there any way with non-blocking more ?
|
Of course. But without seeing your actual code, I couldn't advise you how
to fix your existing code to do so.
Gambit
|
|
| Back to top |
|
 |
joke Guest
|
Posted: Tue Feb 03, 2004 10:22 pm Post subject: Re: Non-blocking mode memory load |
|
|
Here is my simple code which is sending and receiving a file via
TClientSocket and TServerSocket :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
btnSend: TButton;
Client: TClientSocket;
Server: TServerSocket;
procedure FormCreate(Sender: TObject);
procedure ClientConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure btnSendClick(Sender: TObject);
procedure ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FileStrm: TFileStream;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FileStrm := TFileStream.Create('C:copy.exe', fmCreate);
with Server do
begin
Port := 381;
Active := True;
end;
with Client do
begin
Port := 381;
Host := '127.0.0.1';
Active := True;
end;
end;
procedure TForm1.ClientConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
Caption := 'Connected..';
end;
procedure TForm1.btnSendClick(Sender: TObject);
var
FStrm: TFileStream;
begin
FStrm := TFileStream.Create('C:data.exe', fmOpenRead);
Client.Socket.SendStream(FStrm);
end;
procedure TForm1.ServerClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
Buff: Pointer;
RLength, RBuff: integer;
begin
RLength := Socket.ReceiveLength;
try
GetMem(Buff, RLength);
while RLength > 0 do
begin
RBuff := Socket.ReceiveBuf(Buff^, RLength);
if RBuff <= 0 then
begin
Break;
end
else begin
FileStrm.Write(Buff^, RBuff);
end;
end;
finally
FreeMem(Buff);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FileStrm.Free;
end;
end.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|