Board index » delphi » Sending Files through IP sockets

Sending Files through IP sockets

Quote
"DSR" <dsr...@bigfoot.com> wrote in message

news:PC%I4.55$RH.4053@nsw.nnrp.telstra.net...

Quote
> BUT I wish to send FILES, (WAV, BMP, JPEG, VQF, MP3) AS WELL.

You will need to use blocking sockets and a TSocketStream on each end. You
set up a 'conversation' by first sending the filename, receiving a check
byte, sending the filesize, receive another check byte, and then finally
send the file through the socket stream. At the receiving end you will need
to receive the stream in small packets and append these to a memory stream
or file stream.

Joanna

 

Re:Sending Files through IP sockets


Hi All,
            I've created an app, with client and server sockets, which
connect with each other across two or more computers. Text passing between
my app (s), is quite posible, and working well.
METHOD

SENDING : serversocket.socket.connections[0].SENDTEXT('the text');

RECEIVING : memo2.lines.add(socket.receivetext);

SO FAR SO GOOD, I CAN SEND TEXT (AND TEXT FILES).

BUT I wish to send FILES, (WAV, BMP, JPEG, VQF, MP3) AS WELL.

Ok the problem, when I attempt to send a file, eg WAVE or BMP, it dumps a k
or so of gibberish, after I pass it through the memobox (ok, I know, I
didn't think it would work either. I need to buffer through a (large) string
or memorystream).
So figuring it revolved around those damn hard to use STREAMS, I wrote;

SENDING :
stream:=tmemorystream.create;
stream.loadfromfile('c:\file.ext');
ServerSocket.Socket.Connections[0].SendStreamThenDrop(stream);
(this sent I think?)

RECIEVING :
stream:=tmemorystream.create;
filee:='c:\dsr.wav';
stream.SaveToFile(filee);
stream.read(socket.receivetext);
(this doesn't recieve!)

I HOPED
is picture then Image1.picture.bitmap.loadfromstream(stream)
is sound then sndplaysound(stream)
is file then winexec(stream)

Anyhow, try as I might, I can't seem to buffer the filestream into (back
into a file).

I have found examples revolving around "foreign"components, yet wish to try
within Delphi or API.

Regards
DSR
dsr...@bigfoot.com

Re:Sending Files through IP sockets


Assuming, I didn't care where the file when ie save to x for each file.
Overwriting the previous,
How can one break up the file?.
Regards
DSR
Quote
Joanna Carter <Joan...@btinternet.com> wrote in message

news:8d2r9n$fut$1@neptunium.btinternet.com...
Quote
> "DSR" <dsr...@bigfoot.com> wrote in message
> news:PC%I4.55$RH.4053@nsw.nnrp.telstra.net...

> > BUT I wish to send FILES, (WAV, BMP, JPEG, VQF, MP3) AS WELL.

> You will need to use blocking sockets and a TSocketStream on each end. You
> set up a 'conversation' by first sending the filename, receiving a check
> byte, sending the filesize, receive another check byte, and then finally
> send the file through the socket stream. At the receiving end you will
need
> to receive the stream in small packets and append these to a memory stream
> or file stream.

> Joanna

Re:Sending Files through IP sockets


Quote
"DSR" <dsr...@bigfoot.com> wrote in message

news:ZXeJ4.311$qN.5203@nsw.nnrp.telstra.net...

Quote
> Assuming, I didn't care where the file when ie save to x for each file.
> Overwriting the previous,
> How can one break up the file?.
> Regards
> DSR

When you send the file, you use just use SocketStream.CopyFrom(FileStream,
0)
but you will have to set up a small routine to receive the file in chunks as
you cannot guarantee the whole file in one go:

const
  kBlockSize = 1024;

                repeat
                  if fStream.WaitForData(10000) then
                  begin
                    PacketSize := fStream.Read(Buf^,

Min(kBlockSize, FileSize - BytesRecvd));
                    Inc(BytesRecvd, PacketSize);
                    FileStream.Write(Buf^, PacketSize);
                    FillChar(Buf^, kBlockSize, 0);
                  end;
                until (BytesRecvd = FileSize) or (PacketSize = 0);

Ok?

Joanna

Re:Sending Files through IP sockets


Thanks Joanna, ............ for your answer, and your patience.
Kindest Regards
DSR

Quote
Joanna Carter <Joan...@btinternet.com> wrote in message

news:8d5e8h$n43$1@uranium.btinternet.com...
Quote
> "DSR" <dsr...@bigfoot.com> wrote in message
> news:ZXeJ4.311$qN.5203@nsw.nnrp.telstra.net...
> > Assuming, I didn't care where the file when ie save to x for each file.
> > Overwriting the previous,
> > How can one break up the file?.
> > Regards
> > DSR

> When you send the file, you use just use SocketStream.CopyFrom(FileStream,
> 0)
> but you will have to set up a small routine to receive the file in chunks
as
> you cannot guarantee the whole file in one go:

> const
>   kBlockSize = 1024;

>                 repeat
>                   if fStream.WaitForData(10000) then
>                   begin
>                     PacketSize := fStream.Read(Buf^,

> Min(kBlockSize, FileSize - BytesRecvd));
>                     Inc(BytesRecvd, PacketSize);
>                     FileStream.Write(Buf^, PacketSize);
>                     FillChar(Buf^, kBlockSize, 0);
>                   end;
>                 until (BytesRecvd = FileSize) or (PacketSize = 0);

> Ok?

> Joanna

Other Threads