Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

File Transfer

Posted on 2002-06-04
4
Medium Priority
?
268 Views
Last Modified: 2010-05-18
how can i send file from peer to peer (from client to server an the vise versa).
i'm looking for code if available.
Fayiz
0
Comment
Question by:fayiz
4 Comments
 
LVL 1

Accepted Solution

by:
bnemmers earned 1000 total points
ID: 7054281
This code will send a file out a open socket.

procedure TSendDataThread.SendFile;
var
  SocketStream: TWinSocketStream;
  FileStream: TFileStream;
  StreamInfo: TStreamInfo;
  FileName: string;
begin
  FileName := ExtractFileName(fStreamInfo.StreamStr);
  FileStream := TFileStream.Create(fStreamInfo.StreamStr, fmOpenRead or fmShareDenyWrite);
  SocketStream := TWinSocketStream.Create(frmMain.csMain.Socket, 60000);
  try
    if (not Terminated) and (frmMain.csMain.Active) then
    begin
      try
        StreamInfo.StreamCmd := SENDFILECMD;
        StreamInfo.StreamSize := FileStream.Size;
        StreamInfo.StreamStr := FileName;
        SocketStream.Write(StreamInfo, SizeOf(TStreamInfo));
        SocketStream.CopyFrom(FileStream, FileStream.Size);
      except
        if not(ExceptObject is EAbort) then
          Synchronize(HandleExeption);
      end;
    end;
  finally
    frmMain.csMain.Socket.Close;
    SocketStream.Free;
    FileStream.Free;
  end;
end;

Good luck Bill
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7054949
if you prefer blocking sockets using Indy then take a look at :

http://lee.nover.has.his.evilside.org/isapi/pas2html.dll/pas2html?File=/delphi/MiscFiles/vn_common

check out lnVidTypes and lnVidFuncs for SendFile and ReceiveFile
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9010455
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from bnemmers

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

972 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