Article View: borland.public.cppbuilder.internet.socket
Article #4641Re: please help me..socket file transfer
From: Hans Galema
Date: Tue, 11 Jan 2005 13:16
Date: Tue, 11 Jan 2005 13:16
56 lines
2666 bytes
2666 bytes
billaras wrote:
> i want when i click the button to send the file from a serversocket to a
> client socket
Do you mean from a TServerSocket to a TClientSocket ?
> please help me
Please do not put such words in a Subject.
> what is wrong with the code?is it better to use indy components?
TServerSocket/TClientSocket can transfer files or large amounts
of data very well.
> THANK YOU ALL IN ADVANCE FOR YOUR HELP
???
> ServerSocket1->Socket->Connections[0]->SendStream(file);
Check the returnvalue of SendStream(). It is a bool. Only
if true all went well on the sending side.
> void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
> TCustomWinSocket *Socket)
> {
> int iLen;
> Pointer BFR;
What is -the type of- Pointer ?
> iLen=ClientSocket1->Socket->ReceiveLength();
> Memo2->Lines->Add(iLen);
> //GetMem(BFR,iLen);
What does GetMem() ? You need to declare a buffer first that can
be used by ReceiveBuf(). Not only an uninitialized pointer.
> ClientSocket1->Socket->ReceiveBuf(BFR,iLen);
Check the return value of ReceiveBuf with iLen. iLen will most certainly
be less than file->Size on the sending side. So wait for other
events of ClientSocket1Read() to add all bytes up until you got the
complete file. You could let the sender send the size first.
> SaveDialog1->Execute();
> TFileStream *file2 = new TFileStream(SaveDialog1->FileName,fmOpenWrite);
> file2->ReadBuffer(BFR,iLen);
> file2->Write(BFR,iLen);
Are you never checking return values of functions ?
How to implement ClientSocket1Read() has been told often in this
group. You can google for it first.
Hans.
Technical Details
Message-ID:
<41e3d1df@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41e3b756@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,399582d307fda7fe X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 11 Jan 2005 14:16:27 +0100 From: Hans Galema <notused@notused.nl> User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: please help me..socket file transfer References: <41e3b756@newsgroups.borland.com> In-Reply-To: <41e3b756@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 129.125.201.248 Message-ID: <41e3d1df@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1105449439 129.125.201.248 (11 Jan 2005 05:17:19 -0800) Lines: 56 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail