LoginSignup
3
2

More than 5 years have passed since last update.

SWI-Prolog で、Web サーバーを立てる

Last updated at Posted at 2018-10-14

サーバーのプログラムです。

helloweb.pl
#! /usr/bin/swipl -f -q

:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).

server(Port) :-
        http_server(http_dispatch, [port(Port)]).

:- http_handler(/, say_hi, []).

say_hi(_Request) :-
        format('Content-type: text/html~n~n'),
        format('Hello World! Oct/14/2018<p />~n'),
        format('こんにちは。 今日は、10月14日です。<p />~n').

サーバーの実行

server(8000). とキーイン

$ ./helloweb.pl 
?- server(8000).
true.

?-

ブラウザーで、 http://localhost:8000 にアクセス
swipl_oct14.png

サーバーを終了される時は、次のようにキーイン

halt.

次のバージョンで確認しました。

$ swipl --version
SWI-Prolog version 7.6.4 for x86_64-linux
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2