MBS Xojo Conference
6/7th September 2018, Munich

« Why you should try Xo… | Home | FileMaker Cloud 1.17.… »

SSH tunnel in Xojo


As you may know, you can use SSH command line to start a tunnel from your computer through the SSH connection to a server on the other side. For one app, we use the following tunnel for MySQL:

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.
31 05 18 - 11:36
one comment

This seems wrong (extra E?):

if channel.LastError = session.kErrorEagain then
Markus Winter - 31 05 18 - 13:17


  
Remember personal info?

Emoticons / Textile


Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.