|
From: | carlos calderon |
Subject: | sockets in Prolog |
Date: | Mon, 11 Jun 2001 13:08:44 +0100 |
Hi All,
I am trying to pass ALL the solutions generated by
a prolog "solver" to a server. To test this idea I wrote a small
program:
go(X,Y) :-
solve(X,Y),
client(X,Y).
/*where solve yields X and Y taken into account a
series of geometrical constraints*/
solve(X,Y) :-
/*Vars, domains and constraints are defined
here*/
>> This works no problem. It does what's
meant to do.
>>Then to send the data to my server I wrote
the following
client(X,Y) :-
socket('AF_INET'. Socket),
socket_connect(Socket, 'AF_INET' ('152.XXX.XXX.XXX', 2000),
StreamInput,StreamOutput),
/*where XXX is the IP address of my server*/
write_term(StreamOutput, X, []),nl,
write_term(StreamOutput, Y, []),
close(StreamOutput). /*close stream*/
Well, the result I got -looking in the log files-
is:
first line: Accepted 1 1 /*the X and Y coordinate
of a solution*/
>>however when I tried to generate another
solution by keying in ";" The new solution pops up in the prolog side but when
the program tries to pass it on to the server I got the following
message:
Discarding redundant connection
attempt
current socket handle is 360
>>I think it's because my client code closes
the current output stream when "close(StreamOutput)" is called.
>>then I tried the following:
client(X,Y) :-
socket('AF_INET'. Socket),
socket_connect(Socket, 'AF_INET' ('152.XXX.XXX.XXX', 2000),
StreamInput,StreamOutput),
/*where XXX is the IP address of my server*/
repeat,
(X==end_of_file
->!
;
write_term(StreamOutput, X, []),nl,
write_term(StreamOutput, Y, []),fail),
close(StreamOutput). /*close stream*/
>>I get an infinite loop. I think because X==end_of_file it's never
true.
My question is how can I create a loop in prolog to pass ALL the
solutions to the server?
I also thought of two possibilities:
a)
1) dump my results to a file
2) read (from a file) and send (to a server) using a
repeat loop
b) To be certain that output has been delivered use the following built-in
predicate: flush_output/1
That's all folks, I've been stuck with this for the last day or so.
Please, any help it's greatly appreciated.
If the question has been answered before I apologise but I'd be grateful if
someone tells me where the archives of the list are.
Many thanks,
Carlos
|
[Prev in Thread] | Current Thread | [Next in Thread] |