users-prolog
[Top][All Lists]
Advanced

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

Socket communication between GNU prolog and Java.


From: Ugoretzc
Subject: Socket communication between GNU prolog and Java.
Date: Thu, 20 Mar 2003 19:51:27 EST

I have written two short test programs modeled upon code in the CLPGUI application.

Here is the GNU prolog program:
create_server:-
socket('AF_INET',NbSocket),
socket_bind(NbSocket,'AF_INET'(localhost,1000)),
       socket_listen(NbSocket,5),
       socket_accept(NbSocket,I,O),
read(I, Term),
write(O, Term),
close(I),
close(O),
socket_close(NbSocket).

Here is the java program:
import java.io.*;
import java.net.*;

public class JavaToGP
{
   public static void main(String s[]) {
try {
   Socket socket=new Socket("localhost", 1000);       
   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 client (Java program) sends a message to the server, hello, and the server should return the message back to the client.  Either nothing happens when I first run the server, then the client, or else I get a GNU prolog system error concerning the socket_accept predicate.  Any advice?

reply via email to

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