users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Socket communication between GNU prolog and Java.


From: Ugoretzc
Subject: Re: Socket communication between GNU prolog and Java.
Date: Fri, 21 Mar 2003 16:49:01 EST

I have followed your suggestions and made these modications to the two programs:

THE JAVA PROGRAM:
import java.io.*;
import java.net.*;

public class JavaToGP2
{
   public static void main(String s[]) {
try {
   Socket socket=new Socket("localhost", 27311);       
   PrintWriter out= new PrintWriter(socket.getOutputStream(), true);
   BufferedReader in= new BufferedReader(new InputStreamReader(socket.getInputStream()));
           out.println("hello.");
           String line;
           while ((line = in.readLine()) != null) {
               System.out.println(line + "\n");
           }
           
           out.close();
           in.close();
           socket.close();
}
catch (Exception e) {
   System.err.println("JavaToGP error: "+e.getMessage());
}     
   }
}

THE GNU PROLOG PROGRAM:
gui_create_server(Port):-
gui_create_server(localhost,Port).

gui_create_server(Host,Port):-
catch((socket('AF_INET',NbSocket),
      socket_bind(NbSocket,'AF_INET'(Host,Port)),
              socket_listen(NbSocket,5),
              socket_accept(NbSocket,I,O),
      add_stream_alias(I, input_stream),
      add_stream_alias(O, output_stream)),
     X,write(X)).
gui_create_server(_,_):- gui_disconnect.

gui_disconnect:-
catch(close(input_stream),_,true),
catch(close(output_stream),_,true),
abort.
gui_disconnect:- abort.


serve_data:- gui_create_server(27311),
    catch(read(input_stream,R), X, write(catch(X))),
    write('READ '), write(R), nl, flush_output.

I attempted to follow more strictly the format of the CLPGUI program (in fact I copied snippets of it nearly exact, except for socket_accept/4, which I reduced to socket_accept/3 to avoid an error).  When I run the server, and then the client, I get the following error:

error(system_error(Invalid argument),socket_accept/3)catch(error(existence_error(stream,input_stream),read/2))READ _71

I am using a different Windows 98 computer than the one I previously wrote these programs for (see earlier email), but the system error is still the same.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]