Board index » delphi » Send/Receive Files using TClientSocket and TServerSocket

Send/Receive Files using TClientSocket and TServerSocket

Hello

I know this has been asked before, but I really need some code to send
files/records(big) in delphi using TClientSocket and TServerSocket.  Also,
information on how to send using streams would be greatly appreciated.

Thanks in advance

Muhammed-Sharif

 

Re:Send/Receive Files using TClientSocket and TServerSocket


Muhammed-Sharif <muhammed_sha...@hotmail.com> schreef in berichtnieuws
3a4acf50_2@dnews...
Quote
> Hello

> I know this has been asked before, but I really need some code to send
> files/records(big) in delphi using TClientSocket and TServerSocket.  Also,
> information on how to send using streams would be greatly appreciated.

See below for an example how to send socket data from a stream;
The data type is string, but note that you can force any data into a long
string using SetLength() and Move().

Notes :
1. Large amounts of data _will_ arrive in chunks of unpredictable length,
hence the length dword at the head of the stream, which allows the receiving
side to figure out when all data have arrived.
2. You can call the function repeatedly, but if you fork out feed more data
then the network can handle (or the receiving side can handle! ) you'll get
errors...

--
Regards,

Dirk Claessens
---------------------------------------------------------
http://www.claessens16.yucom.be
Attention: All spamshields raised; E-mails will bounce!
---------------------------------------------------------

Usage :
   if not SendSockStream( YourSocket, YourData ) then
      ShowMessage('Oops! We have {*word*88}d Winsock...');

function SendSockStream(Socket: TCustomWinSocket; Data: string): boolean;
var
  TempStream: TMemoryStream;
  StreamLen : DWORD;
begin
  TempStream := TMemoryStream.Create;
  StreamLen  := Length(Data) + SizeOf(StreamLen);
  // write length word at head of stream
  TempStream.Write( StreamLen, SizeOf(StreamLen));
  // write data
  TempStream.Write( Data[1], Length(Data));
  TempStream.Position := 0;
  Result := Socket.SendStream(TempStream);
  // do _NOT_ free stream; socket wil handle this!!

end;

Re:Send/Receive Files using TClientSocket and TServerSocket


Thanks again Dirk!

(you seem to be the only one who answers my questions)

Re:Send/Receive Files using TClientSocket and TServerSocket


"Muhammed-Sharif" <muhammed_sha...@hotmail.com> schrieb im Newsbeitrag
news:3a4c8293_1@dnews...
Quote
> Thanks again Dirk!

> (you seem to be the only one who answers my questions) *********

Perhaps, it is, because most people do not worry about winsock internals
an use a user ready solution like Indy, witch handles blocksize and
other things.

Ernst Gerlach
ernst.gerl...@epost.de
http://www.gerlach-mtl.de
--- use plain text only in email ---

Re:Send/Receive Files using TClientSocket and TServerSocket


Quote
>Perhaps, it is, because most people do not worry about winsock internals
>an use a user ready solution like Indy, witch handles blocksize and
>other things.

I know most people use other solutions like Indy and ICS, but for some
reason (dont ask me why), I dont feel comfortable using 3rd party components

Re:Send/Receive Files using TClientSocket and TServerSocket


"Muhammed-Sharif" <muhammed_sha...@hotmail.com> schrieb im Newsbeitrag
news:3a4ee0e1_1@dnews...
Quote
> >Perhaps, it is, because most people do not worry about winsock internals
> >an use a user ready solution like Indy, witch handles blocksize and
> >other things.

> I know most people use other solutions like Indy and ICS, but for some
> reason (dont ask me why), I dont feel comfortable using 3rd party
components

T_x_Socket is a 3rd party component too, from BORLAND (and absolutly
not the best).
If you want to work without, have a look to gra...@mhn.org,
you can see, how to work without 3rd party.

Ernst Gerlach
ernst.gerl...@epost.de
http://www.gerlach-mtl.de
--- use plain text only in email ---

Re:Send/Receive Files using TClientSocket and TServerSocket


Hi Ernst,

Ernst Gerlachwrote :

[...]

Quote
> T_x_Socket is a 3rd party component too, from BORLAND (and absolutly
> not the best).

[...]
Muhammed wrote about TClientSocket and TServerSocket. These components
are directly from Borland (no 3rd party). I don't know what kind of
component this T_x_Socket is, but it is not part of Delphi. Even the
NetManage stuff has no component with this name.

Juergen

Re:Send/Receive Files using TClientSocket and TServerSocket


a) Sorry, the winsocket is part of windows. Question: is windows developed
by Microsoft or by Borland?
Borland made a encapsulation like many other 3rd party.
b) the "_x_" stands as a placeholder for "id" (Indy) or "nm"  or
...................
c) My feeling is, Borland did a very poor encapsulation, when .....
(sorry continue follows in german in a mail, my english is to bad)

Ernst Gerlach
ernst.gerl...@epost.de
http://www.gerlach-mtl.de
--- use plain text only in email ---

"Juergen Schwarze" <juergen_schwa...@t-online.de> schrieb im Newsbeitrag
news:3a4ff09d_1@dnews...

Quote
> Hi Ernst,

> Ernst Gerlachwrote :

> [...]

> > T_x_Socket is a 3rd party component too, from BORLAND (and absolutly
> > not the best).

> [...]

> Muhammed wrote about TClientSocket and TServerSocket. These components
> are directly from Borland (no 3rd party). I don't know what kind of
> component this T_x_Socket is, but it is not part of Delphi. Even the
> NetManage stuff has no component with this name.

> Juergen

Re:Send/Receive Files using TClientSocket and TServerSocket


Hi,

Ernst Gerlach wrote :

Quote
> a) Sorry, the winsocket is part of windows. Question: is windows developed
> by Microsoft or by Borland?

the whole Windows API is made by Microsoft. But the translations coming with
Delphi are made by Borland. Other translations (e.g. from Jedi) are '3rd party',
because they are based on Borland Delphi.

Quote
> Borland made a encapsulation like many other 3rd party.

Your understanding of the term '3rd party' is a little bit strange. In the context
of Borland Delphi there are two parties, Borland and the customer. Everything
Borland offers to me (the customer) what is made by Borland, is not '3rd party'.
But another company or programmer who offers programs/sources to work together
with Borland Delphi is '3rd party'. So the NetManage components coming with
Borland Delphi are '3rd party'. TClientSocket and TServerSocket are not '3rd party'
by this definition.

Quote
> b) the "_x_" stands as a placeholder for "id" (Indy) or "nm"  or
> ...................

You should have explained that point in your original posting.

Quote
> c) My feeling is, Borland did a very poor encapsulation, when .....

No one could ever really describe me, what's so bad with these two components
TClientSocket and TServerSocket. Is there someone from the Borland staff, who
could tell me about the bugs and shortcomings of these components? OK, they
are very basic socket components, but for a small and simple program I don't
need a full-blown package like Indy or ICS.

Quote
> (sorry continue follows in german in a mail, my english is to bad)

Please don't send me unsolicited eMail.

Juergen

Re:Send/Receive Files using TClientSocket and TServerSocket


"Juergen Schwarze" <juergen_schwa...@t-online.de> schrieb im Newsbeitrag
news:3a50b713_2@dnews...

Quote
> Hi,

> Ernst Gerlach wrote :

> > a) Sorry, the winsocket is part of windows. Question: is windows
developed
> > by Microsoft or by Borland?

> the whole Windows API is made by Microsoft. But the translations coming
with
> Delphi are made by Borland. Other translations (e.g. from Jedi) are '3rd
party',
> because they are based on Borland Delphi.

> > Borland made a encapsulation like many other 3rd party.

> Your understanding of the term '3rd party' is a little bit strange. In the
context
> of Borland Delphi there are two parties, Borland and the customer.
Everything
> Borland offers to me (the customer) what is made by Borland, is not '3rd
party'.
> But another company or programmer who offers programs/sources to work
together
> with Borland Delphi is '3rd party'. So the NetManage components coming
with
> Borland Delphi are '3rd party'. TClientSocket and TServerSocket are not
'3rd party'
> by this definition.

> > b) the "_x_" stands as a placeholder for "id" (Indy) or "nm"  or
> > ...................

> You should have explained that point in your original posting.

> > c) My feeling is, Borland did a very poor encapsulation, when .....

> No one could ever really describe me, what's so bad with these two
components
> TClientSocket and TServerSocket. Is there someone from the Borland staff,
who
> could tell me about the bugs and shortcomings of these components? OK,
they
> are very basic socket components, but for a small and simple program I
don't
> need a full-blown package like Indy or ICS.

> > (sorry continue follows in german in a mail, my english is to bad)

> Please don't send me unsolicited eMail.

Sorry, i did not know, that you are so conceited with your better english
knowlage.
Quote

> Juergen

Stay living with your: nur wo borland draufsteht ist auch borland drin.
good by

Ernst Gerlach
ernst.gerl...@epost.de
http://www.gerlach-mtl.de
--- use plain text only in email ---

Re:Send/Receive Files using TClientSocket and TServerSocket


juergen_schwa...@t-online.de (Juergen Schwarze) wrote in
<3a50b713_2@dnews>:

Quote
>Borland staff, who could tell me about the bugs and shortcomings of these
>components? OK, they are very basic socket components, but for a small and
>simple program I don't need a full-blown package like Indy or ICS.

Two things to consider:

1) Indy will be in Delphi 6 and Kylix. I dont know if that still makes it 3rd
party by your definition or not.

2) With Indy, things are well encapselated. If you use only the base TCP
classes, (or other bases) it will only link in the necessary pieces, not the
whole thing.

--
Chad Z. Hower (Kudzu) - Church Hill, TN - Team Indy
      "Programming is an art form that fights back"
Forget the Y2K problem, Lets fix the W2K problem.
http://www.pbe.com/Kudzu/ - Free Delphi/CBuilder components and articles

Re:Send/Receive Files using TClientSocket and TServerSocket


"Juergen Schwarze" <juergen_schwa...@t-online.de> schrieb im Newsbeitrag
news:3a50b713_2@dnews...

Quote
> Hi,

> Ernst Gerlach wrote :

> > a) Sorry, the winsocket is part of windows. Question: is windows
developed
> > by Microsoft or by Borland?

> the whole Windows API is made by Microsoft. But the translations coming
with
> Delphi are made by Borland. Other translations (e.g. from Jedi) are '3rd
party',
> because they are based on Borland Delphi.

They are NOT based on Borland Delphi, THEY ARE BASED ON THE
WINDOWS API. Dont tell such a stuss.
Switch on your head.

Ernst Gerlach
ernst.gerl...@epost.de
http://www.gerlach-mtl.de
--- use plain text only in email ---

Re:Send/Receive Files using TClientSocket and TServerSocket


Quote
> (you seem to be the only one who answers my questions)

You've set them all off now....

--
Carl.

Quote
"Muhammed-Sharif" <muhammed_sha...@hotmail.com> wrote in message

news:3a4c8293_1@dnews...
Quote
> Thanks again Dirk!

> (you seem to be the only one who answers my questions)

Other Threads