I learned some codes to make a mini HTTP server in MMA way here.
server=SocketListen[8000,Function[{assoc},Block[{client=assoc["SourceSocket"]},
Block[{html,expr},
expr=First@StringCases[assoc["Data"],RegularExpression["GET /\\?expr=([^ ]+)"]->"$1"];
html=ToString@InputForm@ToExpression@URLDecode@expr;
WriteString[client,"HTTP/1.1 200 OK\r\nDate: "<>DateString[]<>"\r\nContent-Type: text/html\r\nContent-Length: "<>
ToString@StringLength@html<>"\n\n"<>html];
Close[client]]]]]
do not forget to close it when finished.
DeleteObject[server]
Close[server["Socket"]]
by the upper codes, we could pass expr
s to MMA and get results in TEXT
s way,
I want to know how to show the Plot
s or Graphics
with these codes in web browsers like Chrome
?
I wonder that, MMA could be used as web server, there should be some framework
s to help this becoming true, like Express
upon node.js
. is this worth to do sth?
ExportString[expr,"PNG"]
and changing the response content-type toimage/png
might work. $\endgroup$HTMLFragment
can help on bothTEXT
orPLOT
s if setContent-Type
valuetext/html
$\endgroup$Exit[]
executed whenWloframAlpha
firstly lanched as public knowledge engine. $\endgroup$