If you can use POST instead of GET, then there is no need to url encode/decode the J sentence. Not sure if jhs understand POST since I'm not too familiar with jhs.
Ср, 11 ноя 2015, Ian Clark написал(а): > Thanks @Bill. > > I guess you meant: http://localhost:65001/foo?i.6 > (missing '1'). Even so, it doesn't work as it stands, even if you > pre-create the locale: 'foo' empty. The locale 'foo' must contain a > verb: jev_get . If you write it right, that's all it need contain. > > Here's a tiny engine, which will accept a URL such as: > http://localhost:65001/jsengine?a=.3&b=.5&a+b > and generate a webpage consisting of the string following the question mark. > > The page content contains no html markup (which suits my purpose, if > not everybody's) – but Firefox will happily display it nonetheless. > > (Curiously, Firefox uses a different sized font on my Mac if you type > 127.0.0.1 in place of localhost.) > > jev_get_jsengine_=: ([: htmlresponse_jhs_ '?' takeafter ' ' taketo > gethv_jhs_) bind 'GET' NB. all-one-line > > This verb needs to be defined in the profile (or startup.ijs) that > jhs.command loads when it launches. Plus other verbs, to provide a > non-trivial J service. > > Any J-er will see how to add further code to jev_get in order to parse > such a string and execute the J phrases it contains, sending back a > string value of the final result as the y-arg of htmlresponse. Also > worth noting that at the point at which jev_get is run, there are two > useful global caches, tables: HNV_jhs_ and NV_jhs_, containing info > about the URL at the other end of the socket. > > Now all that remains is to tweak NSTask to fetch the contents of a > given URL -- and I'm home and dry. > > Ian > > PS: just for fun, here's a 1-line Hello World in the same vein… > > jev_get_hello_=: htmlresponse_jhs_ bind 'Hello World' > > See it with: http://localhost:65001/hello > > On Tue, Nov 10, 2015 at 3:39 PM, bill lam <[email protected]> wrote: > > jhs itself does not depend on javascript. It is the browser front-end that > > uses javascript. Browser is not involved at all if you use wget or curl > > to run J sentences like a cgi such as > > > > wget http://localhost:6500/foo?i.6 > > > > This is a headless server, requires no x window or any other display. You > > can call it a daemon. Of course you need a script that create a locale foo > > on jhs. > > > > or you don't wget/curl at all if your programming environment already has > > library support for http request. > > On Nov 10, 2015 11:16 PM, "Ian Clark" <[email protected]> wrote: > > > >> I'm glad you said that, Bill. > >> > >> JHS solves all the technical problems we've been discussing. It had > >> occurred to me to use it instead of jconsole, but I took one look at > >> the Javascript "baggage" and couldn't decide what was baggage and what > >> was not. > >> > >> wget/curl --you've put your finger on the way in. > >> > >> I'm short of time and having to be ruthless over which lines I pursue. > >> It would re-jig my priorities to see the sample code of: > >> http://jsoftware.com/help/user/cmdline.htm > >> reformulated to use jhs instead of jconsole. > >> > >> On Tue, Nov 10, 2015 at 3:04 PM, bill lam <[email protected]> wrote: > >> > Another way is to keep a running jhs, and send request to it using > >> > wget/curl. It also uses sockets but you need zero knowledge of socket > >> > programming. > >> > On Nov 10, 2015 10:51 PM, "Ian Clark" <[email protected]> wrote: > >> > > >> >> > The problem with the daemon approach is making sure the daemon is > >> alive > >> >> > >> >> Too right, @Joe. > >> >> > >> >> As I said in my (discarded) reply to Raul: > >> >> > >> >> …with all the attendant problems for the client of finding out: have > >> >> you finished yet? -- are you alive? -- are you actually installed? -- > >> >> and package it all up for general release, with no requirement for > >> >> customer customization, and be transparent to the user. The "user" in > >> >> this case being a novice J programmer, who is basically a novice in > >> >> any form of programming. > >> >> > >> >> Why are you and I the only J-ers who see this? :-) > >> >> > >> >> On Tue, Nov 10, 2015 at 2:45 PM, Joe Bogner <[email protected]> > >> wrote: > >> >> >> However, my "silly" solution (suggested earlier) is indeed robust – > >> >> >> and I've just been doing experiments on this: > >> >> >> > >> >> >> $ jconsole -js a=.23 b=.3 "echo a*b" "exit''" > >> >> >> > >> >> > > >> >> > Thanks for elaborating > >> >> > > >> >> > Looks like a solid, simple solution to me. I wouldn't touch the > >> >> > sockets unless there was too much overhead in getting J back to the > >> >> > state desired to execute against (e.g. loading a large file) > >> >> > > >> >> > I've also used the 'silly' solution with J in a webapp awhile back to > >> >> > avoid mucking around with sockets and threads. > >> >> > > >> >> > The problem with the daemon approach is making sure the daemon is > >> alive > >> >> > ---------------------------------------------------------------------- > >> >> > For information about J forums see > >> http://www.jsoftware.com/forums.htm > >> >> ---------------------------------------------------------------------- > >> >> For information about J forums see http://www.jsoftware.com/forums.htm > >> > ---------------------------------------------------------------------- > >> > For information about J forums see http://www.jsoftware.com/forums.htm > >> ---------------------------------------------------------------------- > >> For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm -- regards, ==================================================== GPG key 1024D/4434BAB3 2008-08-24 gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3 gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
