EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Event On_DataReceive?

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#10058
Posted: 05/19/2009 07:09:29
by Plusnet GmbH & Co. KG - (Standard support level)
Joined: 02/04/2009
Posts: 12

Hi,

is there any possibility to realise a "On_DataReceive" Event for SSH Blackbox AX? It`s not so nice to run Client.CanReceive() every secound (with a Timer) to check if there is new data to receive. Do you have any advice or hint for me?

Thank you
Dominik
#10059
Posted: 05/19/2009 07:33:32
by Ken Ivanov (EldoS Corp.)

ElSimpleSSHClientX (I assume you are asking about it?) is designed to be synchronous. Adding asynchronous OnDataReceive event to it would violate its model, and in general is not a trivial task.

Actually, it is not necessary to use a timer. You can run the component in a separate thread and call CanReceive() method in a loop (that is how synchronous classes are usually used).

Besides, you can build your own asynchronous SSH environment using low-level SSHBlackbox classes (ElSSHClientX, ElShellSSHTunnelX, ElSSHTunnelListX etc.).
#10060
Posted: 05/19/2009 07:55:40
by Plusnet GmbH & Co. KG - (Standard support level)
Joined: 02/04/2009
Posts: 12

Hi, thanks for your quick reply...

I don`t understand how to do that. I only have the Expample-Project wich came with SSH Blackbox. There a Timer is used to print the data which is received...

I started a now project for testing what you say:

On a Button_Click event I do this:
Code
Client.Address = "server.ip"
Client.UserName = "user"
Client.Password = "pass"
Client.Command = "echo 'test me'"
Client.Open


Then in the OnSendCommandRequest event I do this:
Code
List1.AddItem ("cmd request " & Command & " " & CmdIndex)
    
Do While (Client.CanReceive(0) = True)
    Client.ReceiveText txtOut, txtErr
    List1.AddItem ("rx " & txtout)
Loop


But this does not work. I only see the "cmd request..." debug message which I write to a listbox. The "CanReceive" method is false when I look at it.

I got parts of this code from the How-To "Execute commands remotely". Would you be so kind to post a litte example for me how to use the ElSimpleSSHClientX as a synchronous class?

Thank you!
Dominik
#10066
Posted: 05/19/2009 12:31:03
by Eugene Mayevski (EldoS Corp.)

But the sample project, provided with the downloadable version, IS synchronous?


Sincerely yours
Eugene Mayevski
#10071
Posted: 05/20/2009 00:44:33
by Plusnet GmbH & Co. KG - (Standard support level)
Joined: 02/04/2009
Posts: 12

Hi,

in my sample project for SimpleSSH there is the following code to display the received Data:

Code
Private Sub Timer1_Timer()
  ' Data arrived to socket
  Dim a As String, b As String

  If (Not Client.Active) Or (Receiving) Then
    Exit Sub
  End If
  
  Receiving = True ' Setting 'Received' flag to prevent recursion (it is possible due to DoEvents call inside MessageLoop)
  
  On Error GoTo ex
  While True
    Client.ReceiveText a, b
    If a <> "" Then
        Memo1.Text = Memo1.Text + a
    Else
        GoTo ex
    End If
  Wend
ex:
  Receiving = False
End Sub


But I am interested how to do this without a Timer...

Thanks
Dominik
#10072
Posted: 05/20/2009 01:08:29
by Eugene Mayevski (EldoS Corp.)

Right logic is

Code
While Client.Active or Client.CanReceive(some timeout)
  if (CanReceive) then
    ReceiveData()
  end if
wend


The fact that CanReceive returns false doesn't mean that you should stop processing of the data. SSH server can send data in any moment of time, that's why you also need to check Active and exactly in the way it's written above.


Sincerely yours
Eugene Mayevski
#10073
Posted: 05/20/2009 02:12:25
by Plusnet GmbH & Co. KG - (Standard support level)
Joined: 02/04/2009
Posts: 12

Hi,

thank you for your help!

Code
Private Sub Command1_Click()
    Dim txtout As String
    Dim txterr As String

    Client.Address = "10.0.0.0"
    Client.UserName = "user"
    Client.Password = "pass"
    Client.Commands.Add ("ls -la")
    Client.Open
    
    While Client.Active = True Or Client.CanReceive(0) = True
        If Client.CanReceive(0) = True Then
            Client.ReceiveText txtout, txterr
            debug.print txtout
        End If
    Wend
    
    Client.Close
End Sub


This works... For all who are searching for this :-)

Dominik
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

Topic viewed 1312 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!