14
$\begingroup$

Whenever a Link is created using LinkCreate or LinkLaunch with LinkProtocol -> "TCPIP", Mathematica opens up two ports for communicating with the attached process. Can these be specified by the user of these functions?

I ask because it would allow me to route all communication over ssh via port-forwarding.

$\endgroup$
1

2 Answers 2

12
$\begingroup$

If you want to use port forwarding, you'll need to know that for every MathLink connection, two different ports are used. The full syntax for TCPIP link names looks like this:

LinkCreate["[email protected],[email protected]", LinkProtocol -> "TCPIP"] 

8000 and 8001 are the port numbers while 1.2.3.4 is your IP address. You can pass only a single port number to LinkCreate as the link name: in this case it will return a LinkObject containing the full name and the other port will be automatically selected.


However, if you want to use SSH port forwarding, I strongly recommend using the Remote Kernel Strategies package. It will save you a lot of trouble. For example, it will automatically forward ports for all three links that Mathematica needs for Front End - Kernel communication ($ParentLink, MathLink`$PreemptiveLink and MathLink`$ServiceLink). The other two links are created by the kernel when the front end connects to it by executing the code in the file SystemFiles/FrontEnd/TextResources/GetFEKernelInit.tr.

Please see the presentation I linked to for more information on how the connection is made and why three links are needed.

$\endgroup$
3
  • $\begingroup$ Reading through the pdf now. Incidentally, it says that mathssh does do public key authentication, but my experience was different. I wonder why that is so. $\endgroup$ Commented Jan 26, 2012 at 2:10
  • $\begingroup$ @rcollyer With Remote Kernel Strategies you don't need to rely on mathssh. On Windows it uses putty. On Unix-based systems I guess it uses whatever ssh the system has .. $\endgroup$ Commented Jan 26, 2012 at 18:33
  • $\begingroup$ I read through the shell script, and yes it uses ssh not mathssh. $\endgroup$ Commented Jan 26, 2012 at 18:35
7
$\begingroup$

From the docs:

LinkCreate["8000", LinkProtocol -> "TCPIP"] 

Further down that page is shown:

This connects to the port on frog.wolfram.com.

link = LinkConnect["[email protected],[email protected]", LinkProtocol -> "TCPIP"] 
$\endgroup$
1
  • $\begingroup$ I like this answer because you deliver the source as well. That should be standard practice if you ask me. $\endgroup$ Commented Jan 25, 2012 at 18:20

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.