I would like to dedicate a small machine to exclusively running a Mathematica kernel and use that kernel to read http requests arriving on port 80, treat them and send http responses back without any web server or extra software of any kind. Requests are to be treated in sequence (only 1 connection shall be supported at a time). Clearly webMathematica is an overkill here. Any ideas?
-
11$\begingroup$ This usage is not permitted by the Mathematica licence: you need webMathematica, even if technically you don't. Practically speaking, it's not possible with no extra software at all since Mathematica has no facilities to work with TCP sockets, but you can use Java, a .Net language, or C to fill in the gaps. $\endgroup$– Oleksandr R.Jun 27, 2013 at 21:56
-
7$\begingroup$ It seems to me that using Mathematica to answer http requests is already "overkill." $\endgroup$– bill sJun 28, 2013 at 6:11
-
4$\begingroup$ There is now a built-in socket interface but it's undocumented and I have not sorted out a safe way of reading from the input stream. mathematica.stackexchange.com/questions/72551/… $\endgroup$– MBrynJan 27, 2015 at 4:03
-
$\begingroup$ If you are using Mathematica 11.2 or later, see this answer. $\endgroup$– FluxMay 19, 2019 at 4:08
4 Answers
From Oleksandr's comment:
This usage is not permitted by the Mathematica license: you need webMathematica, even if technically you don't. Practically speaking, it's not possible with no extra software at all since Mathematica has no facilities to work with TCP sockets, but you can use Java, a .Net language, or C to fill in the gaps.
The specific statement can be found in the Mathematica License Agreement, under Prohibited Uses, section f:
allowing access to the Product by any user other than Licensee, including, without limitation, access to the Product via a web server, which is only allowed pursuant to a valid webMathematica™ license agreement;
and section j:
using a password, activation key, or other means of accessing the Software other than as specifically authorized by WRI;
-
-
$\begingroup$ @william. I'm not a lawyer so you have to think for yourself. If you're the only user section f could be interpreted as allowing it though section j suggests otherwise. $\endgroup$ Feb 27, 2015 at 16:22
-
$\begingroup$ It seems the license agreement has been changed. webMathematica is not mentioned any more. $\endgroup$– SilviaJul 30, 2019 at 3:31
This is node.js that creates a local server if you are experimenting.
Again this isn't legal to use on something other then a local port.
var http = require('http');
var loc = "C:/Users/a/Desktop/node.m test";
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
var exec = require('child_process').exec,
child;
child = exec('"C:/Program Files/Wolfram Research/Mathematica/10.0/Math" -noprompt -script '+loc,
function (error, stdout, stderr) {
console.log('stderr: ' + stderr);
res.end(
(stdout).replace(/\\n/g,"\n").slice(1,-3)
);
if (error !== null) {
console.log('exec error: ' + error);
}
});
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
-
3$\begingroup$ This doesn't seem to answer the question because it is not a Mathematica-based solution. $\endgroup$ Mar 14, 2015 at 22:40
-
$\begingroup$ @m_goldberg True but according to this question mathematica.stackexchange.com/questions/72551/… There isn't one that works $\endgroup$– JonMar 14, 2015 at 22:43
Yes (and using pure Mathematica or WolframEngine)
In the new 10.3 version, you can write in WlL the logic of your app/website and generate HTTP responses. See the documentation.
-
2$\begingroup$ There are no new functions in 10.3 that will allow you to set up an HTTP server, as far as I know. That documentation page that you link to can't help. $\endgroup$– C. E.Nov 11, 2015 at 0:25