Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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: stackoverflow.com/questions/8717211/… –  Szabolcs Jan 25 '12 at 18:42
add comment

2 Answers 2

up vote 10 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@1.2.3.4,8001@1.2.3.4", 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.

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
add comment

From the docs:

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

Further down that page is shown:

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

link = LinkConnect["2981@frog.wolfram.com,2982@frog.wolfram.com", 
         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. –  ndroock1 Jan 25 '12 at 18:20
add comment

Your Answer

 
discard

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.