TScSSHChannel.readbuffer

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
MRoth
Posts: 14
Joined: Thu 30 Sep 2021 01:06

TScSSHChannel.readbuffer

Post by MRoth » Sun 03 Oct 2021 02:22

Hello,

Can someone send us an example on how to implement the TScSSHChannel.readbuffer and writebuffer.

We can not find an example on your website or in the demos.

Thanks

YanishevskiyVI
Devart Team
Posts: 70
Joined: Wed 02 Jun 2021 09:30

Re: TScSSHChannel.readbuffer

Post by YanishevskiyVI » Wed 06 Oct 2021 14:57

Hi Maria,

Please be informed TScSHHChannel.Readbuffer and TScSHHChannel.Readbuffer sample code can be found in

Code: Select all

%Documents%\Devart\SecureBridge for XXX\Demos\Indy9\ScIndy.pas
%Documents%\Devart\SecureBridge for XXX\Demos\Indy10\ScIndy.pas
Usage sample:

Code: Select all

var
  buf: TBytes;
...
  Channel.Connect;
...
//perform writing
  Channel.WriteBuffer( buf, length( buf ) );
...
//perform reading
  Channel.ReadBuffer( buf, length( buf ) );
//or
  Channel.ReadNoWait( buf, length( buf ) );
...
  Channel.Disconnect;
alternatively, perform reading with event handler

Code: Select all

  Channel.OnAsyncReceive:=AsyncReceive;//TNotifyEvent type
...

procedure TDataModule.AsyncReceive(Sender: TObject);
var
  buf:TBytes;
begin
  with Sender as TScSSHChannel do begin
    SetLength( buf, InCount );
    ReadBuffer( buf, length( buf ) );
    //process received data
  end;
end;
Regards,
Vitaliy

MRoth
Posts: 14
Joined: Thu 30 Sep 2021 01:06

Re: TScSSHChannel.readbuffer

Post by MRoth » Wed 06 Oct 2021 19:34

Thank you.

If we are not using Asyncreceive to read the data but are using your first example. Can we use incount to check if there is any data in the buffer. We have a timer that will check incount every 100 milliseconds to see if there is any data in the buffer. If incount is greater than 0 then we do what you have in your second example.:

SetLength( buf, InCount );
ReadBuffer( buf, icount );

YanishevskiyVI
Devart Team
Posts: 70
Joined: Wed 02 Jun 2021 09:30

Re: TScSSHChannel.readbuffer

Post by YanishevskiyVI » Tue 12 Oct 2021 08:11

Hi!

Thank you for your reply!

Please be informed, that InCount property is specially dedicated to use with Read Buffer method, thus your code will work.

Also, in order to increase the code efficiency, it is a good idea in case of InCount=0 to omit buffer adjustments and reading operation.

Please note that using OnTimer event instead of OnAsyncReceive is very time inefficient!

Please, let us know if you have any questions!

Regards,
Vitaliy

Post Reply