parent
bfdf36babb
commit
9e459a9d1d
@ -0,0 +1,29 @@
|
||||
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).
|
Loading…
Reference in new issue