:- use_module(library(sockets)).

%각 client의 전략에 따라 묵,찌,빠 중 하나를 선택해준다.
%make_turn(-MZB).
make_turn('mook').

go(Port) :- 
	write('this is client!!!'), nl,

	socket_client_open('143.248.134.99':Port, Stream,[type(text)]),	
	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,!.
	
