Hi, I'm working with a GNU Prolog socket problem. I saw this mailing-list when I searched the web for solutions.
I try to create a Prolog code that works in lke this Java code: http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/networking/sockets/examples/EchoClient.java I try to make a client that listen for user inputs and writes the user input to the socket. The server echo the data from the socket back to the socket and to the client, that output the data on the screen. Here is my code: % The Client client_init :- socket('AF_INET',Socket), socket_connect(Socket,'AF_INET'(localhost,7002),SI,SO), add_stream_alias(SO, out), add_stream_alias(SI, in), set_stream_buffering(out, line). client_send:- repeat, read(T), % user input ( B \== end_of_file -> ( format(out, '~q~n',[T]),write(out), % send over socket read_term(in,B,[end_of_term(eof)]), % read the result write(B), nl, % write on screen nl, fail ) ; !), close(out), close(in). % The Server server :- socket('AF_INET', Sock), socket_bind(Sock, 'AF_INET'(localhost, 7002)), socket_listen(Sock, 4), socket_accept(Sock, C, SI, SO), format('accepting a connection from client: ~a~n', [C]), repeat, read(SI, T), ( T \== end_of_file -> write(T), nl, write(SO,T), nl, fail ; !), close(SI), socket_close(Sock). Best Regards Jan-Olof Janson ________________________________________________________________________________ <http://www.lightmotion.se>
_______________________________________________ Users-prolog mailing list Users-prolog@gnu.org https://lists.gnu.org/mailman/listinfo/users-prolog