How to communcate to the client from TScSSHServer?

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
hsn
Posts: 5
Joined: Fri 11 Sep 2015 20:53

How to communcate to the client from TScSSHServer?

Post by hsn » Fri 11 Sep 2015 21:15

On my test ScSSHClient Application I have two TScSSHChannel objects, both are connected to the same TScSSHClient. TScSSHChannel-A is used to send various information back and forth between the Client Application and the Server Application. TScSSHChannel-B is used to secure a database connection between the two machines. I am facing some problems while trying to send data back and forth on my Channel-A

For the Channel-A I am using

Code: Select all

Direct=True
NonBlocking=True,
DestHost=ScSSHServer Application IP Address
DestPot=ScSSHServer Listening Port
This is how I am trying to use it:

1a. when ScSSHClient Application wants to send a text message to the server, I call

Code: Select all

Channel-A.WriteString('My Message from Client');
1b. the message is received on the ScSSHServer Application in DataFromClient event.

2a. when the server decides to send a message to a particular client, it identifies an appropriate client-channel from ScSSHServer.ChannelInfos[] and send the text message by using the method:

Code: Select all

ScSSHServer.SendToClient(ScSSHServer.ChannelInfos[i], 'Message from the Server', 23);
2b. The message is received by the client at AsyncReceive event handler, as Channel-A.ReadString

Is this the right way to use it?

Thanks!

hsn
Posts: 5
Joined: Fri 11 Sep 2015 20:53

Re: How to communcate to the client from TScSSHServer?

Post by hsn » Mon 14 Sep 2015 15:41

Can someone tell me how to use the following two methods?

SSHServer.SendToClient()
and
SSHChannel.WriteString()

My test program is created as per the recommendation in the post
http://forums.devart.com/viewtopic.php? ... ent#p95875

As soon as I send something to the server (Direct, Non-Blocking), the channel loses its connection.
Is is necessary to call Channel.Connect; each time before sending any data to the server?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: How to communcate to the client from TScSSHServer?

Post by ViktorV » Tue 15 Sep 2015 07:24

To create channel only for data exchanging with SSH server you should set Direct to True in the TScSSHServer.BeforeChannelConnect event handler, like this:

Code: Select all

  Direct := True;

hsn
Posts: 5
Joined: Fri 11 Sep 2015 20:53

Re: How to communcate to the client from TScSSHServer?

Post by hsn » Tue 15 Sep 2015 14:00

ViktorV wrote:To create channel only for data exchanging with SSH server you should set Direct to True in the TScSSHServer.BeforeChannelConnect event handler, like this:

Code: Select all

  Direct := True;
That worked!

Actually that code was present as described in the thread that I posted but the statement did not get executed because of a bug in my code. Thanks a lot for your help!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: How to communcate to the client from TScSSHServer?

Post by ViktorV » Tue 15 Sep 2015 14:12

It is good to see that the problem has been solved.
Feel free to contact us if you have any further questions about SecureBridge.

hsn
Posts: 5
Joined: Fri 11 Sep 2015 20:53

Re: How to communcate to the client from TScSSHServer?

Post by hsn » Tue 15 Sep 2015 15:34

Thanks!

Is the event TScSSHServer.BeforeChannelConnect supposed to be fired only for a Channel with Direct := true?

(I am still using 2.60 from 2010. Some of these things might have changed since then I suppose)

Edit-1: Looks like just making the channel.Connected to be true on the client does not fire this event on Server for non-Direct connections. I noticed the same behavior with the demo projects as well (SimpleSSHServer and SSHClient). But in the demo client project, on btSConnectClick, a socket is created and manually connected using ConnectSocket helper. is that really required? Or is there an easier way to accomplish this in newer versions?

Edit-2: Looks like when Channel.Direct is not true, BeforeChannelConnect gets fired on the server only when you start using the channel for communication and not when you enable the Channel.Connected.

Channel.Connect does not actually establishes a connection to the server. Server side BeforeChannelConnect gets fired each time you use a client to connect to your service through the SSH Server using that Channel.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Re: How to communcate to the client from TScSSHServer?

Post by Dimon » Fri 18 Sep 2015 10:24

When the TScSSHChannel.Direct property is set to True, then on calling TScSSHChannel.Connect a new channel with server is created, and respectively the TScSSHServer.BeforeChannelConnect event is raised.
If the TScSSHChannel.Direct property is False, then the component starts listening to the SourcePort on the local host, and creates the new channel only when someone connects to this port. Accordingly, at that moment the TScSSHServer.BeforeChannelConnect event is raised.
In the btSConnectClick method of our SSHClient demo, a connection to TScSSHChannel.SourcePort is emulated to demonstrate the above functionality. In practice, this can be applied when, for example, you already have a client working with a database, and it needs to implement connection via a protected channel using SSH. In such case, you run TScSSHChannel with Direct := False, that listens to the specified port - and the database client now connects to this port. At this, TScSSHChannel creates a protected channel with SSH server and transfers database client data over this channel. SSH server decrypts the data - and transfers it over unprotected channel.

hsn
Posts: 5
Joined: Fri 11 Sep 2015 20:53

Re: How to communcate to the client from TScSSHServer?

Post by hsn » Fri 18 Sep 2015 15:02

Thanks Dimon and ViktorV!
I got it working now..

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: How to communcate to the client from TScSSHServer?

Post by ViktorV » Mon 21 Sep 2015 13:28

If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.

Post Reply