File Transferring Using TCP/IP

Hi,
It is great to feel that some one stands behind you.I really appreciate your work.Ihave aquestion :
how to transfer a file(larger than 32kbyte)using TCP\IP?
THANKS
Rihab
rihabAsked:
Who is Participating?
 
XANConnect With a Mentor Commented:
you can use TCP/IP ClientSocket and ServerSocket to establish connection between they. I prefere blocking connection. ServerSocket open listen socket on spesified port (let it is N). ClientSocket connects to Server through the port (N). ServerSocket with ThreadBlocking connection create TServerClientThread for the connected client. You should define own successor from TServerClientThread with overloaded ClientExecute method. The method should use TWinSocketStream to do real data transfer (input and outpu).
It may be like this:

procedure TMyClientThread.Execute;
var
  TheSocketStream: TWinSocketStream;
  buffer: string;
begin
  { create a TWinSocketStream for reading and writing }
  TheSocketStream := TWinSocketStream.Create(ClientSocket1.Socket, 60000);
  try
    { fetch and process commands until the connection or thread is terminated }
    while (not Terminated) and (ClientSocket1.Active) do
    begin
      try
        GetNextRequest(buffer); { GetNextRequest must be a thread-safe method }

        { write the request to the server }
        TheSocketStream.Write(buffer, Length(buffer) + 1);
        { continue the communication (eg read a response from the server) }
        ...
      except
        if not(ExceptObject is EAbort) then
          Synchronize(HandleThreadException); { you must write HandleThreadException }
      end;
    end;
  finally
   TheSockettream.Free;
  end;
end;

it possible use TFileStream to file read/write operations

FS := TFileStream.Create(myFile, fmFileMode);
FS.SaveToStream(TheSocketStream);
FS.Free;
0
 
rihabAuthor Commented:
SHOULD I use threads and how?
0
 
MotazCommented:
Can you stablish a connection between to computers?

If you did you can slit a file into packets you can use untyped files, (BlockRead) then send it as a binarry buffers, but you have to send the file size inorder to send the data of the file.

You do not need to use Threads to send file, only you can use Application.ProcessMessages; in the loop of sending and reading file to allow other application processes to take place.

Offcourse this is not an answer so that let other experts write thier openion of this topic.

Good luck

Motaz
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
wmckieCommented:
I don't have a definitive answer for you but you might find help at these web sites. Both are sets of useful free components with many examples.

http://www.rtfm.be/fpiette/indexuk.htm

http://www.pbe.com/winshoes/

Also if you can use ftp you could look at this VB example:

http://www.mvps.org/vbnet/code/network/ftpdofiledownload.htm

I haven't tried it but it uses a procedure in shdocvw.dll (IE 5 only I think).

Good luck

Walter McKie
0
 
haehnenCommented:
Listening...
0
 
yk030299Commented:
I remember there are 2 components: TFtpClient & TFtpServer in FPiette Package
0
 
ranmanorCommented:
Use streams.
0
 
bryan7Commented:
all you need is here..
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10104621 

just transfer a file using TFileStream in stead of the image..
0
 
rihabAuthor Commented:
thank alot for your answer it was so helpful
0
All Courses

From novice to tech pro — start learning today.