Re: [twsocket] TWsocket transfer TmemoryStream

2016-12-06 Thread François Piette
> Always is needed use the OnDataSent event ?
> I need only transfer the tmemorystream off a Timage1 to Timage2 over
twsocket.

You may send a huge block of data in one Send call. An entire image if you
like. BUT remember TWSocket is asynchronous and transmitting data over the
network takes time. You call to the Send method will return almost
instantly, way long before the data is actually sent: TWSocket will
automatically buffer the data in memory and send it in the background for
you. This may take a lot of memory if you send large data. This may be of no
importance for your application, or it IS important...

When using OnDataSent event, you have control on the size of data that is
memorized. For example you can read your stream 4KB (Any value is OK) at a
time, send that chunk of data and then read the next chunk from the
OnDataSent event, that is the next chunk will be read and put in internal
TWSocket buffer only when previous chunk is sent. This is how the HTTP
component (both client and server) are working to send data. This way it
doesn't matters if a multi GB file is sent. The memory used is always the
size of the chunk your application read.


--
francois.pie...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be



-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWsocket transfer TmemoryStream

2016-12-06 Thread Angus Robertson - Magenta Systems Ltd
> Always is needed use the OnDataSent event ?
> I need only transfer the tmemorystream off a Timage1 to Timage2 
> over twsocket.

It will probably work on a LAN, as long as BLOCK_SIZE is no more than
64 KBytes, and the server accepts the data immediately it's sent.  

But the proper way is to send chunks in OnDataSent, then you know the
other end is accepting the data.  

The sample OverbyteIcsSender.dpr illustrates how to use OnDataSent to
send the next block.  

Or you could just use my ICS TMagIpLog component, that will send and
receive a stream. 

https://www.magsys.co.uk/delphi/magics.asp

That component also uses OnDataSent to send a stream, if you want to
borrow the code, but using the proper component would be faster. 

Angus

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWsocket transfer TmemoryStream

2016-12-05 Thread Fatimire
Always is needed use the OnDataSent event ?
I need only transfer the tmemorystream off a Timage1 to Timage2 over twsocket.



Sent from [ProtonMail](https://protonmail.ch), encrypted email based in 
Switzerland.



 Original Message 
Subject: Re: [twsocket] TWsocket transfer TmemoryStream
Local Time: 5 de Dezembro de 2016 5:31 PM
UTC Time: 5 de Dezembro de 2016 19:31
From: fatim...@protonmail.com
To: ICS support mailing <twsocket@lists.elists.org>

procedure TForm1.SendClick(Sender: TObject);
var
Buffer: array [1..BLOCK_SIZE] of char;
Count: Integer;
MemoryStream : TMemoryStream;
begin
try
MemoryStream := TMemoryStream.Create;
img1.Picture.Graphic.SaveToStream(MemoryStream);
MemoryStream.Seek(0, soFromBeginning);
WSocketServer1.Client[0].SendStr(IntToStr(MemoryStream.Size) + #13#10);

Count := MemoryStream.Read(Buffer[1], BLOCK_SIZE);
if Count > 0 then
WSocketServer1.Client[0].Send(@Buffer[1], Count);
if Count < BLOCK_SIZE then ShowMessage('Sended');
except end;

end;

Its Ok ?


Sent from [ProtonMail](https://protonmail.ch), encrypted email based in 
Switzerland.



 Original Message 
Subject: Re: [twsocket] TWsocket transfer TmemoryStream
Local Time: 5 de Dezembro de 2016 3:19 PM
UTC Time: 5 de Dezembro de 2016 17:19
From: an...@magsys.co.uk
To: twsocket@lists.elists.org

> I need help to send text and stream in same socket

Sending text and stream data is simple, just use Send, although if your
stream is larger than a few kilobytes you need to send it in chunks,
check whether it's been sent, then send the next chunk.

This is how the HTTP client component works.

Receiving mixed text and stream data is much harder, because you don't
generally know where one stops and the other starts. So you design a
protocol, an example being HTTP again, where a blank line says text
stops and stream starts, the stream length being content-length long or
when the socket closes.

Angus

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWsocket transfer TmemoryStream

2016-12-05 Thread Fatimire
procedure TForm1.SendClick(Sender: TObject);
var
Buffer: array [1..BLOCK_SIZE] of char;
Count: Integer;
MemoryStream : TMemoryStream;
begin
try
MemoryStream := TMemoryStream.Create;
img1.Picture.Graphic.SaveToStream(MemoryStream);
MemoryStream.Seek(0, soFromBeginning);
WSocketServer1.Client[0].SendStr(IntToStr(MemoryStream.Size) + #13#10);

Count := MemoryStream.Read(Buffer[1], BLOCK_SIZE);
if Count > 0 then
WSocketServer1.Client[0].Send(@Buffer[1], Count);
if Count < BLOCK_SIZE then ShowMessage('Sended');
except end;
end;

Its Ok ?


Sent from [ProtonMail](https://protonmail.ch), encrypted email based in 
Switzerland.



 Original Message 
Subject: Re: [twsocket] TWsocket transfer TmemoryStream
Local Time: 5 de Dezembro de 2016 3:19 PM
UTC Time: 5 de Dezembro de 2016 17:19
From: an...@magsys.co.uk
To: twsocket@lists.elists.org

> I need help to send text and stream in same socket

Sending text and stream data is simple, just use Send, although if your
stream is larger than a few kilobytes you need to send it in chunks,
check whether it's been sent, then send the next chunk.

This is how the HTTP client component works.

Receiving mixed text and stream data is much harder, because you don't
generally know where one stops and the other starts. So you design a
protocol, an example being HTTP again, where a blank line says text
stops and stream starts, the stream length being content-length long or
when the socket closes.

Angus

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWsocket transfer TmemoryStream

2016-12-05 Thread Angus Robertson - Magenta Systems Ltd
> I need help to send text and stream in same socket

Sending text and stream data is simple, just use Send, although if your
stream is larger than a few kilobytes you need to send it in chunks,
check whether it's been sent, then send the next chunk.

This is how the HTTP client component works. 

Receiving mixed text and stream data is much harder, because you don't
generally know where one stops and the other starts.  So you design a
protocol, an example being HTTP again, where a blank line says text
stops and stream starts, the stream length being content-length long or
when the socket closes. 

Angus

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be