Re: raw TCP/IP socket communication in mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg17428] Re: raw TCP/IP socket communication in mathematica
- From: "P.J. Hinton" <paulh>
- Date: Thu, 6 May 1999 02:44:31 -0400
- Organization: "Wolfram Research, Inc."
- References: <Pine.GSU.4.05.9905041712540.21049-100000@flip.eecs.umich.edu>
- Sender: owner-wri-mathgroup at wolfram.com
On Tue, 4 May 1999, Daniel Reeves wrote: > 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)} -- P.J. Hinton Mathematica Programming Group paulh at wolfram.com Wolfram Research, Inc. http://www.wolfram.com/~paulh/