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).
# 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 >

# 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?