?
Solved

Sockets and Streams

Posted on 2003-03-20
4
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

762 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