It seems like the only way is to have a C program as an intermediary...
Thanks,
Daniel
-- -- -- -- -- -- -- -- -- -- -- --
Daniel Reeves http://ai.eecs.umich.edu/people/dreeves/
"I wish people who have trouble communicating would just shut up."
-- Tom Lehrer
Daniel Reeves wrote:
>
> Is there a way for mathematica to talk to arbitrary (not just mathlink
> compatible) programs over TCP/IP sockets?
>
> It seems like the only way is to have a C program as an intermediary...
Exact that is the only way.
Otherwise tell my standalone (not networked) MS-Windows PC that a TCP/IP
socket is.
Regards
Jens
It should be straightforward to implement this in the kernel by having an
option for LinkConnect that says "Raw". Then all LinkWrite's and
LinkRead's would send and receive plain strings.
Does this sound feasible for a future version?
-- -- -- -- -- -- -- -- -- -- -- --
Daniel Reeves http://ai.eecs.umich.edu/people/dreeves/
"Drawing on my fine command of language, I said nothing."
On Mon, 3 May 1999, P.J. Hinton wrote:
> > Is there a way for mathematica to talk to arbitrary (not just mathlink
> > compatible) programs over TCP/IP sockets?
> >
> > It seems like the only way is to have a C program as an intermediary...
>
> Your suspicions are correct. The MathLink API does not expose the
> internals of the transport protocol. Normally this would be desirable
> if you wanted to write a program that was capable of using more than
> one type of interprocess communication. It looks as if in your case
> this is more of a liability.
>
> --
> P.J. Hinton
> Mathematica Programming Group pa...@wolfram.com
> Wolfram Research, Inc. http://www.wolfram.com/~paulh/
> Disclaimer: Opinions expressed herein are those of the author alone.
>
> I think the ability to send and retrieve arbitrary strings over TCP
> sockets is very important. The specific application I have in mind is
> creating bidding agents that participate in an online auction (part of my
> research on artificial intelligence for ecommerce). This type
> of application is becoming more and more common and I think it's important
> that Mathematica support communication with programs other than mathlink
> compatible ones. Bots that gather data on the web is another example of
> why this would be necessary.
>
> It should be straightforward to implement this in the kernel by having an
> option for LinkConnect that says "Raw". Then all LinkWrite's and
> LinkRead's would send and receive plain strings.
Alternatively, you could build an installable MathLink binary that defines
a top-level interface to your operating system's native socket API. That
would be a highly reusable component that could be launched whenver
needed.
Below is an example of a top-level interface to the Unix system call
uname(). You could create a MathLink template like this:
:Begin:
:Function: myuname
:Pattern: SystemInformation[]
:Arguments: {Null}
:ArgumentTypes: Manual
:ReturnType: Manual
:End:
and then the C code would look something like this:
#include <sys/utsname.h>
#include "mathlink.h"
void myuname(void);
void myuname(){
struct utsname unamedata;
int retval;
retval = uname(&unamedata);
if(retval == 0){
MLPutFunction(stdlink, "List", 6);
MLPutString(stdlink, unamedata.sysname);
MLPutString(stdlink, unamedata.nodename);
MLPutString(stdlink, unamedata.release);
MLPutString(stdlink, unamedata.version);
MLPutString(stdlink, unamedata.machine);
MLPutString(stdlink, unamedata.domainname);
}
else{
MLPutSymbol(stdlink, "$Failed");
}
return;
}
int main(int argc, char *argv[]){
return MLMain(argc, argv);
}
I can now get the result of uname from my installed function.
In[1]:= Install["myuname`"]
Out[1]= LinkObject['./myuname.exe', 1, 1]
In[2]:= LinkPatterns[%1]
Out[2]= {SystemInformation[]}
In[3]:= SystemInformation[]
Out[3]= {Linux, monon, 2.0.0, #1 Mon Jun 10 21:11:56 CDT 1996, i586,
(none)}
http://ai.eecs.umich.edu/people/dreeves/misc/math-sockets/
It includes a sample notebook that grabs an arbitrary webpage from the
internet and spits out the contents. About 4 lines ("link to socket
library", "connect to web site", "ask for web page", "receive response").
I still think raw TCP/IP communication should be part of the kernel. To
Jens's comment that it can't be because his windows box can't do it, I
have 2 responses: 1, his machine would fail to create any link to a
remote machine, "Raw" or otherwise. 2, Mathematica does not take a lowest
common denominator approach to operating system functionality, eg, piping
to external programs is supported in Mathematica even though it won't work
on some operating systems.
So again I'd like to urge Wolfram developers to consider including this
functionality in the kernel. I'd like to see Mathematica become the
language of choice for things like "intelligent internet agents" (like
bidding agents for online auctions) and not having built-in ability to
send and receive data over the internet is a big enough hurdle to prevent
that from happening. Compiling/porting/etc something like what I've done
is a huge headache. But inside the kernel, this problem is already solved
-- there just needs to be an option to turn off enforcement of the
structured, mathlink-packet-based communication and use raw strings
instead.
PS: When I first posted my message about my MASH thing, I accidentally
didn't have the source code (mash.c) visible. It's now there at
http://ai.eecs.umich.edu/people/dreeves/misc/mash/
Thanks,
Daniel
-- -- -- -- -- -- -- -- -- -- -- --
Daniel Reeves http://ai.eecs.umich.edu/people/dreeves/
"'Artificial Intelligence' ceases to be 'intelligent' as soon as it's
actually implemented." -- Uluc Saranli
Mitja Lakner
On 1 May 1999 17:14:46 -0400, Daniel Reeves <dre...@eecs.umich.edu>
wrote:
>Is there a way for mathematica to talk to arbitrary (not just mathlink
>compatible) programs over TCP/IP sockets?
>
>It seems like the only way is to have a C program as an intermediary...
>
>Thanks,
>Daniel
>
>-- -- -- -- -- -- -- -- -- -- -- --
>Daniel Reeves http://ai.eecs.umich.edu/people/dreeves/
>