Page 1 of 1

TScSSHChannel.readbuffer

Posted: Sun 03 Oct 2021 02:22
by MRoth
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

Re: TScSSHChannel.readbuffer

Posted: Wed 06 Oct 2021 14:57
by YanishevskiyVI
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

Re: TScSSHChannel.readbuffer

Posted: Wed 06 Oct 2021 19:34
by MRoth
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 );

Re: TScSSHChannel.readbuffer

Posted: Tue 12 Oct 2021 08:11
by YanishevskiyVI
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