chat_agent:- chat_agent(guest). chat_agent(Name):- chat_agent(Name,_Topic,localhost,7001,none). chat_agent(Name,Topic,Host,Port,Password):- set_topic(Topic), name<=Name, host<=Host, port<=Port, password<=Password. chat:- bg(listen), talk. get_topic(T):-topic=>about(T). set_topic(T):-topic<=about(T). run(Goal):- host=>H, port=>P, password=>W, remote_run(H,P,Goal,Goal,W,the(Goal)). listen:- get_topic(T), listen(T). listen(Topic):- run(random(X)), run(out(listener(Topic,X))), repeat, ( run(in(message(Topic,X,Mes)))-> write_message(Mes),fail ; ! ), run(cin(listener(Topic,X))). say(Topic,Mes):- run(all(listener(Topic,X),Xs)), foreach( member(listener(Topic,X),Xs), run(out(message(Topic,X,Mes))) ). talk:- name=>Sender, get_topic(T), repeat, ( read_message(Sender,Mes)-> say(T,Mes),fail ; ! ). test:- Sender=guest, repeat, ( read_message(Sender,Message)-> write_message(Message),fail ; ! ). read_message(Sender,Mes):- write_unquoted(Sender), write_unquoted('<=: '), readln(Line), Line\==bye, Line\== '$null', atom_codes(Line,Content), Mes=from(Sender,Content). write_message(Mes):- Mes=from(Sender,Content), write(Sender),write_unquoted(':=> '), foreach(member(C,Content),put_code(C)),nl.