You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
760 B
30 lines
760 B
route('/about', 'Read all about it!').
|
|
route('/cool', 'The coolest page on this server.').
|
|
route('/', '\
|
|
iHello From Prolog! \n\
|
|
0About\t/about\tlocalhost\t7777\n\
|
|
0Cool\t/cool\tlocalhost\t7777\n').
|
|
|
|
read_line(Stream, Line) :-
|
|
read_line(Stream, '', Line).
|
|
|
|
read_line(_, Content, Line) :-
|
|
atom_concat(Line, '\r\n', Content).
|
|
|
|
read_line(Stream, Content, Line) :-
|
|
get_char(Stream, Char),
|
|
atom_concat(Content, Char, Next),
|
|
read_line(Stream, Next, Line).
|
|
|
|
main :-
|
|
socket('AF_INET', Socket),
|
|
socket_bind(Socket, 'AF_INET'(_,7777)),
|
|
socket_listen(Socket, 1),
|
|
socket_accept(Socket, StreamIn, StreamOut),
|
|
read_line(StreamIn, Line),
|
|
route(Line, Output),
|
|
write(StreamOut, Output),
|
|
flush_output(StreamOut),
|
|
close(StreamIn),
|
|
close(StreamOut).
|