Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Socket's halfs and XML read/write

Thread view: 
Alex - 10 Nov 2005 02:45 GMT
I try to make simple Client/Server connection wrapped in XML.
So, I create XML request, open connection to the server and send it.
On the server side XML (as ImputStream) is rterieved by
DocumentBuilder.parse().
It means that to finish parse InputStream should be closed.
That's what I do from Client side. Send XML and do
socket.shutdownOutput();
Only after this DocumentBuilder (on server side) finishes its work and
returns Documnent.
But then I want to create XMl answer and send it back for Client.
But both halfs of the socket are already closed.
Don't know why.
On Client side it says:
isInputShutdown=false isOutputShutdown=true
On server side:
isInputShutdown=false isOutputShutdown=false
Server: send the answer xml
Server: java.net.SocketException: Socket closed

I expect that Input and Output halfs of the socket from both sides work
separately but it looks that when I close or OutputShutdown output it
closes both streams.
Looks strange for me.

Any ideas?
Any other way to communicate Client/Server with sending/receiving XML?

Of course I can read input, store it, wait for end of XML, create
virtual InputStream (not closing socket's one), have Document, create
Document-Answer, write it back and only then close both input/output.
But it doesn't look elegant.

So, any suggestions?

Alex.
Robert M. Gary - 10 Nov 2005 02:52 GMT
Why not have the client close the socket after he receives the
response?
Alex - 10 Nov 2005 03:24 GMT
That's what I'm talking about.
How else DocumentBuilder could know that XML is finished?
It waits for the end of the InputStream. It makes perfect sense.
Alex.
John C. Bollinger - 11 Nov 2005 03:50 GMT
> I try to make simple Client/Server connection wrapped in XML.
> So, I create XML request, open connection to the server and send it.
[quoted text clipped - 29 lines]
>
> So, any suggestions?

Have you looked into Socket.shutdownOutput()?  It seems like that would
do what you're looking for.  If you're using a URLConnection on the
client side, then try invoking getInputStream() on it before closing its
output stream.  If none of that is helpful then you'll need to provide
details about what classes and methods the client is using to
communicate; a complete but minimal example code would be best.

Signature

John Bollinger
jobollin@indiana.edu

Alex - 11 Nov 2005 17:04 GMT
Thanks for answer.
I do use shutdown. It's clear from this:
isInputShutdown=false isOutputShutdown=true

Source is not necessary because it's not source question.
After a lot of thinking :) I had undertsood that there is no solution
for my problem.
All frameworks solve it in own way. You have to read whole stream,
understand that it's finished, do work, send answer, then close both
input/output.

It's extra work for me to understand by my own that stream already send
all information even it's not closed. It would be much more convinient
if I could close input or output stream (as mark that it's done) and
still use other one.
Unfortunately it doesn't work. And that was my question - why it
doesn't work and what is regular way to work when it's not working.

Again, after thinking, I understood that it's not solved. Also I didn't
want to create buffer to read and store input and then procceed it.
So, I created my own BreakableInputStream class which extends
InputStream and used it inside but pretend to be closed and send only
EOF when mark of finish had arrived.
I used the same as regular HTTP separator \r\r.
So, when \r\r comes BreakableInputStream pretend to be closed. When
real InputStream is still open. So I can inform in this way
DocumentBuilder that it can proceed parse of XML and finish it's job.
Then I have XML Document, then I send answer by socket output and then
I close both input/output for socket without no harm.
Such a long boring way only because I can't shutdown input/output in
socket separately! What a shame...

Thanks for answer anyway.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.