[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
GNU Prolog - Java sockets communication
From: |
Tiago Loureiro |
Subject: |
GNU Prolog - Java sockets communication |
Date: |
Mon, 25 Oct 2004 16:43:48 +0100 (BST) |
Greetz
I'm writting this because I'm really desperate trying
to communicate from my JAVA client to a GNU PROLOG
server.
I've used, for tests only, the code provided by Daniel
Diaz on the thread "UDP sockets", for the PROLOG
server:
server :-
socket('AF_INET', Sock),
socket_bind(Sock, 'AF_INET'(localhost, 7000)),
socket_listen(Sock, 4),
socket_accept(Sock, C, SI, SO),
close(SO),
format('accepting a connection from client :
~a~n', [C]),
repeat,
read(SI, T),
( T \== end_of_file ->
write(T), nl,
fail
; !),
close(SI),
socket_close(Sock).
client_init :-
socket('AF_INET',Socket),
socket_connect(Socket,'AF_INET'(localhost,7000), SI,
SO),
close(SI),
add_stream_alias(SO, out),
set_stream_buffering(out, line).
client_send(T):-
format(out, '~q.~n',[T]),
write(out).
client_term :-
close(out).
And my JAVA code is something like:
import java.net.*;
import java.io.*;
public class X{
public static final String
SERV_HOST="127.0.0.1";
public static final int SERV_PORT=7000;
public static void main(String [] args){
try{
String s = "";
while (true){
Socket socket = new
Socket(SERV_HOST,SERV_PORT);
ObjectOutputStream oStream = new
ObjectOutputStream(socket.getOutputStream());
BufferedReader in
= new BufferedReader(
new
InputStreamReader(System.in));
s = in.readLine();
oStream.writeObject(s);
socket.close();
}
}
catch (java.io.IOException ex){
ex.printStackTrace();
(sorry for the code formatting from the mail client)
I understand that the problem is that the PROLOG
server needs to get the socket stream input with a
certain formating other than the one my JAVA client is
providing.
My questions:
What is the best way for me to send data through the
client?
What sort of formating does it need to be accepted by
the PROLOG server?
Thank you for reading this newbie's request for help :)
___________________________________________________________ALL-NEW Yahoo!
Messenger - all new features - even more fun! http://uk.messenger.yahoo.com
- GNU Prolog - Java sockets communication,
Tiago Loureiro <=