 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Daneel Guest
|
Posted: Sun Dec 05, 2004 12:54 pm Post subject: File transfer using Indy component - problem |
|
|
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
|
Posted: Fri Feb 25, 2005 1:01 pm Post subject: Re: File transfer using Indy component - problem |
|
|
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 |
|
 |
|
|
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
|
|