15
$\begingroup$

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?

$\endgroup$
4
  • 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$ Commented Jun 27, 2013 at 21:56
  • 7
    $\begingroup$ It seems to me that using Mathematica to answer http requests is already "overkill." $\endgroup$
    – bill s
    Commented Jun 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$
    – MBryn
    Commented Jan 27, 2015 at 4:03
  • $\begingroup$ If you are using Mathematica 11.2 or later, see this answer. $\endgroup$
    – Flux
    Commented May 19, 2019 at 4:08

4 Answers 4

8
$\begingroup$

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;

$\endgroup$
3
  • $\begingroup$ What about locally hosting a web server? $\endgroup$
    – William
    Commented Feb 27, 2015 at 1:27
  • $\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$ Commented Feb 27, 2015 at 16:22
  • $\begingroup$ It seems the license agreement has been changed. webMathematica is not mentioned any more. $\endgroup$
    – Silvia
    Commented Jul 30, 2019 at 3:31
5
$\begingroup$

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/');
$\endgroup$
2
  • 3
    $\begingroup$ This doesn't seem to answer the question because it is not a Mathematica-based solution. $\endgroup$
    – m_goldberg
    Commented 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$
    – Jon
    Commented Mar 14, 2015 at 22:43
1
$\begingroup$

Yes (and using pure Mathematica or WolframEngine)

https://jerryi.github.io/tinyweb-mathematica/

$\endgroup$
0
$\begingroup$

In the new 10.3 version, you can write in WlL the logic of your app/website and generate HTTP responses. See the documentation.

$\endgroup$
1
  • 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.
    Commented Nov 11, 2015 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.