SSH tunnel in Xojo

e.g.
/usr/bin/ssh -L localhost:3307:localhost:3306 -N xxxx@1.2.3.4
We my not do the same in Xojo, but we can tunnel ourselves a connection with the new SSH2SessionMBS.OpenDirectTCPIPChannel function in the upcoming 18.3 plugins. This function opens a tunnel, so you can send data. Your data first goes through SSH connection and than through a TCP/IP connection to the server on the other side. Here is an example:
//* Open tunnel */
dim channel as SSH2ChannelMBS = session.OpenDirectTCPIPChannel("monkeybreadsoftware.de", 80)
if channel = nil then
print "Unable to open a channel"
Return 4
end if
// don't block
channel.SetBlocking false
app.DoEvents 10
// send http request through server to mbs website
dim request as string
request = "GET /cgi-bin/ip.cgi HTTP/1.1"+_
EndOfLine.windows+_
"Host: monkeybreadsoftware.de"+_
EndOfLine.windows+_
EndOfLine.windows
app.DoEvents 10
call channel.Write request
// now see if we get the IP of server returned
do
app.DoEvents 10
dim s as string = channel.Read(10000)
if channel.LastError = session.kErrorEagain then
// no answer yet
Continue
elseif s <> "" then
// got answer
print s
else
// no more data
exit
end if
loop
channel.Close
channel = nil
If you'd use a local server socket to listen for incoming connections, you could have your socket feed data through the tunnel and do the same as the command line. But please be aware that we will use the command line tool in future as it's much easier than coding it all ourselves and without any threading trouble.If you like to test, you can contact us for a preview of the new Network plugin.