MathLink portnumbers and internal types
- To: mathgroup@smc.vnet.net
- Subject: [mg10937] MathLink portnumbers and internal types
- From: f94stbe@dd.chalmers.se (Stefan Berglund)
- Date: Sat, 14 Feb 1998 00:53:13 -0500
- Organization: Engineering Physics, Chalmers University of Technologhy
I wish to have a process to communicate via mathlink peer to peer to a remote computer. The problem is that I a start new mathlink connections as needed from forked processes and I have found no way of telling wich portnumber has been chosen. The problem will probably be solved if I knew how the internal mathlink types MLINK (struct MLink) and MLENV (struct ml_environment) is constructed, the info should be in them. I have searched the online help, The Mathematica book and the mathlink tutorial. I have looked in mathlink.h, mprep generated code and from the debugger. The simple answer is that these types is hidden inside the libML.a library file. I have also seen references to the MathLink Reference but where do I find such a creature (if its not the one in The Book). I do desperatly hope for a real reference with all functions, types and description of error status and so on. All official documentation I have read so far leaves a _lot_ to be desired. The outline of my system is: ***************** Mathematica end: ----------------- (* Install main link *) link=Install["12345@some.host", LinkMode->Connect] (* Read data of new link that will be used after this *) newlink=LinkRead[link] (* Close main link *) Uninstall[link] (* Setup communication link *) (* I will of course have to rebuild the newlink data at some end so that Install will accept it *) comlink=Install[newlink, LinkMode -> Connect] . . . (* Close remote process *) LinkWrite["Finished"] (* Uninstall communication link *) Uninstall[commlink] *************** Parent process: --------------- /* Init Mathlink */ stdenv=MLInitialize(0); /* Open up first link */ link=MLOpenString(stdenv, "-linkname 12345 -linkcreate", &err); while(1) { /* Wait for connection on first link */ MLActivate(link); /* Spawn a subprocess */ pid=fork(); if(pid) { exec("childprocess 12345"); } } *************** Child process: --------------- /* Init mathlink */ env=MLInitialize(0); /* Open communication link to mathematica */ commlink=MLOpenString(env, "-linkcreate", &err); /* Tell mathematica the port I got but */ /* how do I know which port that is? */ MLPutString(link, commlink); /* Wait for connection */ MLActivate(commlink); /* Read communication link */ while(1) { switch(MLGetNext(commlink)) { . . . } } ***************** I will be very grateful for any pointers! -- /Stefan f94stbe@dd.chalmers.se Life - the ultimate practical joke finger f94stbe.pgp@dd.chalmers.se for public pgp-key