Solved

File Transfer

Posted on 2002-06-04
4
255 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 250 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now