How to use Sockets to send/recieve Strings in XML form?
Hello there to everyone reading my Post !
I am entering a total new subject in my learning about Java Programming, where I will need to interact with a server, I was wondering If somebody could help me with a Question I have; here it is:
A server provided me a Socket, (and that is of course an IP address and a Port), And I am supposed to connect to that server using a Java program that connects to servers using a Socket class, then I am supposed to send a String representing a valid XML, and then the server replies me With another String representing a valid XML which I am supposed to store in a String type.
Is thisexact write/read operationpossible? If so, could someone please give me some code samples to solve this problem?
PD: The server Does this operation only: recieve/send Strings. as its called transactional switch.
[888 byte] By [
BCE_Josea] at [2007-11-26 12:51:54]

# 1
Yep.
If you already have the XML in a String, java.io.BufferedWriter.write()/newLine()/flush() will send it, and java.nio.BufferedReader.readLine() will read it.
If you already have the XML as a DOM object, there are numerous techniques involving the javax.xml.transform and javax.xml.transform.stream packages.
ejpa at 2007-7-7 16:40:15 >

# 2
Hi ejp, thank you very much for the quickest of replies.
I am wondering If could you please give me a more detailed source code sample, and the reasons are:
Well, first I am a newbie. and secondly, and most importantly, I actually can try to send the String that represents the XML, but then...
I don't have any idea about how to know when my program has finished sending the String. and therefore I wouldn't know where to put the lines of code that start reading the corresponding response String.
Could you please help me out?
PD: I've been using DOM to read XMLs. Does DOM Objects also allow to read/write XMLs using Sockets?
Thanks in advance!
# 4
Hi, ejp.
Let's say I'm not using non-blocking I/O, so when the method that writes it returns.... I could put the lines of code that read From the server using a Socket, and the server Will respond with a String that corresponds to the String That was sent?
I just have this HUGE doubt as you can see. please help me. and If it is not much of a trouble please please please do put some code snippets.
Sorry for all the trouble, I just trully need this a Lot!
God Bless you.