MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: MathLink portnumbers and internal types



> 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.

It would be bad to expose MLINK and MLENV to user tinkering.
Implementational details of data types such as these are hidden to make
it easier to keep MathLink source code compatible from one revision of
Mathematica to the next.  If programmers rely on internal knowledge of
these structures, then the compatibility issue becomes a very difficult
one.  Much the similar philosophy is taken in many other API's; for
example, the Win32 API similarly hides implementational details for
handles to windows, device contexts, fonts, brushes, etc.

The correct thing to do is to have an API whereby you can query the
attributes of an MLINK or MLENV as required.  There is, in fact, an API
that queries the information you need from an MLINK pointer; if you
look in mathlink.h, you'll see the following:

/* MLName returns a pointer to the link's name.
 * Links are generally named when they are created
 * and are based on information that is potentially
 * useful and is available at that time.
 * Do not attempt to deallocate the name's storage
 * through this pointer.  The storage should be
 * considered in read-only memory.
 */
MLDECL( kcharp_ct, MLName,    ( MLINK mlp)); MLDECL( long,     
MLNumber,  ( MLINK mlp)); MLDECL( charp_ct,  MLSetName, ( MLINK mlp,
kcharp_ct name));

So, MLName returns a const char * pointer to the linkname (i.e.
"####@host" for a TCP connection).  I think (but don't recall for
certain) that MLNumber returns the actual socket number (for a TCP
connection) from that.

Incidentally, I agree that you shouldn't have to go mucking about in
mathlink.h to try to get this information; unfortunately, I don't know
of anywhere else where this particular information is documented.

> I will be very grateful for any pointers!
> 
> -- 
> 			/Stefan
> 			f94stbe@dd.chalmers.se

Sincerely,

John Fultz
jfultz@wolfram.com
Front End Group
Wolfram Research, Inc.



  • Prev by Date: No Subject
  • Next by Date: Help
  • Prev by thread: MathLink portnumbers and internal types
  • Next by thread: Re: MathLink portnumbers and internal types