Board index » delphi » Sending a binary file using TClientSocket and TServerSocket

Sending a binary file using TClientSocket and TServerSocket

Hello everybody,

Could anybody explain to me how I can send a binary file using a
non-blocking TClientSocket and a blocking (threaded) TServerSocket?

Any help would be very much appreciated.

Vinz.

 

Re:Sending a binary file using TClientSocket and TServerSocket


assuming, that the server sends to the client:

Server Side:
use a TWinSocketStream object, to send the file. You'll have to split up the
file yourself into a number of smaller packets that can be sent with the
write method of the stream. You can try to send the whole file in with one
call of write, but this is generally not advisable (the chances that it
works that way are rather small)

Client Side:
wait for the OnRead event and store all the incoming data somewhere until
the whole file has been receive.

assuming, that the client sends to the server:

Client Side:
use sendstream to send the file as a stream. don't forget that you must not
free the stream yourself!!

server side:
use a TWinSocketStream object to receive the stream in consecutive packages.

note, that you should either send the size of the stream beforehand, or at
least mark the end of the stream, so that the other side knows when to stop
receiving.

Andy
--
Kyoto Now !

Other Threads