?
Solved

Sockets and Streams

Posted on 2003-03-20
4
Medium Priority
?
252 Views
Last Modified: 2010-04-04
Greetings

How do I go about transfering a file from the server to the client via sockets upon request from the client.

Would this involve streams ? Any pointers or code would be more than welcome.

Thanx in advance.
0
Comment
Question by:Engwi
  • 2
4 Comments
 
LVL 3

Expert Comment

by:emadat
ID: 8175507
Look at the sample application at:
http://www.tietovayla.fi/BORLAND/delphi/FILES/fileserv.zip

You will find more description under Delphi 3.0, demo #12 at:
http://www.tietovayla.fi/BORLAND/delphi/d_files.htm

Emad
0
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 8175732
listening
0
 

Author Comment

by:Engwi
ID: 8180499
emadat,

Thanx , that demo helped alot ! Another question though , I now receive the file back from the server and well in a String buffer.

How would I go about writing the file to the harddrive on the client side. Would I use the write methods of the TFileStream class ? What would be the best way to handle this.

Thanx in advance.
0
 
LVL 3

Accepted Solution

by:
emadat earned 60 total points
ID: 8181236
That's possibel.

However; the fastest way to write a string to a file is to use BlockWrite as follows:
//====================================================
var
    F: file;
begin
    AssignFile(F, _File_Name_);
    Rewrite(F, 1);
    BlockWrite(F, sData[1], Length(sData));
    CloseFile(F);
end;
//====================================================

Where _File_Name_ is the file name and path and sData is the string contains your data.

If you need to append to an existing file; then you use the following code instead:

//====================================================
var
    F: file;
begin
    AssignFile(F, _File_Name_);
    if FileExists(_File_Name_)
     then Reset(F, 1)
     else Rewrite(F, 1);
    Seek(F, FileSize(F));
    BlockWrite(F, sData[1], Length(sData));
    CloseFile(F);
end;
//====================================================

I hope this will help you
Emad
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question