File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes SocketHandler / BufferedReader question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "SocketHandler / BufferedReader question" Watch "SocketHandler / BufferedReader question" New topic
Author

SocketHandler / BufferedReader question

J. Ryan
Greenhorn

Joined: Jul 24, 2006
Posts: 21
I'm writing a simple client/server application that will make use of logging over a network. My client sends LogRecord objects to a SocketHandler which sends XML data to the server. For some reason when I read the data on the server I'm not getting the closing tag for the root element, </log>.

I'm basing my code on this example posted on Sun's website. Running their code will demonstrate the problem. I duplicated their code below...

Client


Server


Is there something I'm missing here? Thanks.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

The problem is that the element </log> is the tail of the log message according to the XmlFormatter.
The message tail is appended only when you close the handler.
Since, you have programatically added the handler to the logger, you need to close it programatically. So, if you add handler.close() as the last statement in your client, you will get the end element also.
The other option is to specify the handler in the logging.properties file. If you do this the handler will automatically be close when VM exits.


apigee, a better way to API!
J. Ryan
Greenhorn

Joined: Jul 24, 2006
Posts: 21
Thank you. That fixed it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SocketHandler / BufferedReader question