Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Related:… – Szabolcs Jan 25 '12 at 18:42
up vote 11 down vote accepted

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["8000@,8001@", LinkProtocol -> "TCPIP"]

8000 and 8001 are the port numbers while 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/

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

share|improve this answer
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. – rcollyer Jan 26 '12 at 2:10
@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 .. – Szabolcs Jan 26 '12 at 18:33
I read through the shell script, and yes it uses ssh not mathssh. – rcollyer Jan 26 '12 at 18:35

From the docs:

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

Further down that page is shown:

This connects to the port on

link = LinkConnect[",", 
         LinkProtocol -> "TCPIP"]
share|improve this answer
I like this answer because you deliver the source as well. That should be standard practice if you ask me. – nilo de roock Jan 25 '12 at 18:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.