Article View: borland.public.cppbuilder.internet.socket
Article #4897File transfer using Indy component - problem
From: daneel17fr
Date: Sun, 05 Dec 2004 12:58
Date: Sun, 05 Dec 2004 12:58
125 lines
4044 bytes
4044 bytes
Hello,
I am trying to make a client-server application for
file transfers.
The client is expected to send a file to the server
using the Indy
components.
The file is gonna be sent by the client, received by
the server. then,
the server uses TFileStream for creating the local
copy of the file,
and finally writes in it.
But my programs are not fully eficient : I think I
have a problem with
the end of files.
For example, if the sent file is a mp3 file : no
problem, the file is
well received and can be read by any Winamp-like soft.
But, if it is a office file, a zip file or anything
like that, the
received copy is unreadable. In all this cases, the
opening error
message is "Unexpected end of file".
If I am right, the end of file is not "important" for
mp3... you could
cut it in 2 and read the first part without problem.
Has someone an idea about my problem ?
Thank you :-)
________________________________________
piece of code - server
________________________________________
try
{
this->SaveDialog1->Execute();
file = new
TFileStream(this->SaveDialog1->FileName,
fmCreate);
this->myAThread->Connection->ReadStream(file,this->file_size,false);
this->myAThread->Connection->ReadLn("$",1);
this->myAThread->Connection->WriteLn("ok$");
this->myAThread->Connection->Disconnect();
file->Free();
this->Button4->Enabled = false;
this->Memo1->Lines->Add("File
received.");
}
catch (Exception &e)
{
this->Memo1->Lines->Add("A
unidentified error
occurs.");
}
________________________________________
piece of code - client
________________________________________
try
{
this->IdTCPClient1->WriteLn("TRANS1$"); // tag
for sending
this->IdTCPClient1->WriteLn("here the
options$"); // no option
yet
this->IdTCPClient1->WriteLn(this->Edit3->Text+"$");
//the name
of the file
temp_size = this->flot->Size;
this->IdTCPClient1->WriteLn(temp_size+"$"); //
sends the file
size
//this->IdTCPClient1->OpenWriteBuffer(-1);
this->IdTCPClient1->WriteStream(this->flot);
//this->IdTCPClient1->CloseWriteBuffer();
result = this->IdTCPClient1->ReadLn("$",3);
if (result == "refuse")
{
this->Memo1->Lines->Add("File has been
refused by the
server.");
this->Memo1->Lines->Add("The server has
closed he
connexion.");
this->IdTCPClient1->Disconnect();
}
else
if (result == "ok")
this->Memo1->Lines->Add("File has been
received by the
server.");
else
this->Memo1->Lines->Add(result);
this->Button3->Enabled = false;
this->flot->Free();
}
catch (Exception &e)
{
this->Memo1->Lines->Add("An error occurs
during the
transfer.");
}
Technical Details
Message-ID:
<41b30605$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!colt.net!easynet-monga!easynet.net!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 11508e,3274b678507ba70d,start X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "daneel17fr" <nospam.daneel17fr@yahoo.fr> Sender: "daneel17fr" <nospam.daneel17fr@yahoo.fr> Reply-To: "daneel17fr" <nospam.daneel17fr@yahoo.fr> Subject: File transfer using Indy component - problem Newsgroups: borland.public.cppbuilder.internet.socket X-User-Info: 130.230.144.182 NNTP-Posting-Host: 207.105.83.66 Message-ID: <41b30605$1@newsgroups.borland.com> Date: 5 Dec 2004 04:58:45 -0800 X-Trace: newsgroups.borland.com 1102251525 207.105.83.66 (5 Dec 2004 04:58:45 -0800) Lines: 125 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!colt.net!easynet-monga!easynet.net!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail