BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

File transfer using Indy component - problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet)
View previous topic :: View next topic  
Author Message
Daneel
Guest





PostPosted: Sun Dec 05, 2004 12:54 pm    Post subject: File transfer using Indy component - problem Reply with quote



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.");
}
Back to top
John Borchers
Guest





PostPosted: Fri Feb 25, 2005 1:01 pm    Post subject: Re: File transfer using Indy component - problem Reply with quote



Daneel,

First you need to go back to the basics. It's very important to use
checksums to verify data sending / receiving. Use at minimum a 32 Bit CRC so
you can tell what is going wrong.

John

"Daneel" <daneel17fr (AT) yahoo (DOT) fr> wrote

Quote:
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.");
}



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.