Page 1 of 1
How to communcate to the client from TScSSHServer?
Posted: Fri 11 Sep 2015 21:15
by hsn
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!
Re: How to communcate to the client from TScSSHServer?
Posted: Mon 14 Sep 2015 15:41
by hsn
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?
Re: How to communcate to the client from TScSSHServer?
Posted: Tue 15 Sep 2015 07:24
by ViktorV
To create channel only for data exchanging with SSH server you should set Direct to True in the TScSSHServer.BeforeChannelConnect event handler, like this:
Re: How to communcate to the client from TScSSHServer?
Posted: Tue 15 Sep 2015 14:00
by hsn
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:
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!
Re: How to communcate to the client from TScSSHServer?
Posted: Tue 15 Sep 2015 14:12
by ViktorV
It is good to see that the problem has been solved.
Feel free to contact us if you have any further questions about SecureBridge.
Re: How to communcate to the client from TScSSHServer?
Posted: Tue 15 Sep 2015 15:34
by hsn
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.
Re: How to communcate to the client from TScSSHServer?
Posted: Fri 18 Sep 2015 10:24
by Dimon
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.
Re: How to communcate to the client from TScSSHServer?
Posted: Fri 18 Sep 2015 15:02
by hsn
Thanks Dimon and ViktorV!
I got it working now..
Re: How to communcate to the client from TScSSHServer?
Posted: Mon 21 Sep 2015 13:28
by ViktorV
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.