Communicating with non-java app via xml through socket

i need to pass some xml to a non-java server over a socket which i am doing like this:

socket =new Socket(hostname, 23);

out =new PrintWriter(socket.getOutputStream(),true);

in =new BufferedReader(new InputStreamReader(socket.getInputStream()));

now, as far as i understand, i can send info to the server using out.println(xmlData).

but then there will be a delay until the xml reply comes back. do i set up a listener on the BufferedReader and then when there is an event, read from it using something like in.readLine()?

could someone please post some code for doing this, or inform me of another way for going about reading the input back in?

thanks for your help (in advance).

[898 byte] By [deanoemckea] at [2007-11-27 1:41:41]
# 1

> now, as far as i understand, i can send info to the

> server using out.println(xmlData).

> but then there will be a delay until the xml reply

> comes back.

Any delay depends only on how fast your server processes requests.

> do i set up a listener on the BufferedReader

No, there's no API for that

> and then when there is an event

or that

> read from it using something like in.readLine()?

Yes. That's all you have to do.

> could someone please post some code for doing this,

String line;

while ((line = in.readLine()) != null)

{

// your code here

}

in.close();

ejpa at 2007-7-12 0:57:21 > top of Java-index,Core,Core APIs...
# 2

cheers for your help.

im dealing with an eftpos machine so there will be large delays in response while waiting for the user to enter their details and the transaction to get processed. If i use the code that you provided, it will try to read from the socket immediately after writing to it and there will be nothing in the BufferedReader. what is the best way to tackle this problem? perhaps some kind of polling? maybe:

while ((line = in.readLine()) == null) {

sleep;

}

?

or is there a better way?

deanoemckea at 2007-7-12 0:57:21 > top of Java-index,Core,Core APIs...
# 3
It will block until there is data. It will only return null when the other end closes the socket.
ejpa at 2007-7-12 0:57:21 > top of Java-index,Core,Core APIs...
# 4

thanks for your help. seeing as the other end is never going to close the socket (as it is unaware of my presence) i have added a flag to the while loop which will break out when it gets set to false (which happens after the appropriate xml message is received and processed.

Should be all good now. thanks for your help.

deanoemckea at 2007-7-12 0:57:21 > top of Java-index,Core,Core APIs...
# 5
How can the other end not be aware of your presence if it is sending data to you?
ejpa at 2007-7-12 0:57:21 > top of Java-index,Core,Core APIs...