:- use_module(library(sockets)).

%각 client의 전략에 따라 묵,찌,빠 중 하나를 선택해준다.
%make_turn(-MZB).
make_turn('mook').

go(Port) :- 
	write('this is client!!!'), nl,
	socket('AF_INET', My_Socket),
	
	socket_connect(My_Socket, 'AF_INET'('143.248.134.99', Port), Stream),	
	repeat,
	serve_client(Stream),
	socket_close(My_Socket).	
	
serve_client(Stream) :-
	flush_output(Stream),
	read(Stream, Request),
	write('Message from server: '), write(Request), nl,
	serve(Request, Stream).

serve(connected, Stream) :-
	fail.
	
serve(result-X, Stream) :-
	write(X), nl,
	fail.
	
serve(select, Stream) :-
	make_turn(Turn),
	format(Stream, '~w.~n', [Turn]),
	flush_output(Stream),
	fail.

serve(end, Stream) :-
	true,!.
	
