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");
}
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?