java.net.SocketException: Broken pipe

Posted on 2005-04-01
Medium Priority
Last Modified: 2011-10-03
I'm using this code ServletOutputStream to export image to file. It works OK on window, but on unix, sometime it works, sometime it doesn't work and I got an exeption java.net.SocketException: Broken pipe
Please help
Question by:nphnhi
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 35

Expert Comment

ID: 13680446
Are you flushing the stream?

I take it you are sending it to a webbrowser?

It could be that the browser is closing or moving off the page before the image is shown...


Author Comment

ID: 13680458

            try {
                  ServletOutputStream out = response.getOutputStream();
                  response.setHeader("Content-disposition", "attachment;filename=" + filename);
                  int      index = chartnumber - 1;
                  String cdl = ((NFGraph) ngraph.elementAt(index)).getCDL();
                  NFGraph chart = NFGraph.getGraphFromTemplate(cdl);
                  NFImageGeneration.writeImage(chart, imagetype, out);
            } catch (Exception ex) {
                  logger.error( "" + ex);
                  return -1;

Author Comment

ID: 13680471
As TimYates said, if that, how can I solve it???
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 35

Expert Comment

ID: 13680478
Not sure you can...  if the user is just navigating away from the page, the pipe will be broken...

Author Comment

ID: 13680633
I saw what's wrong, in fact, I have a jsp page which calls a servlet to export a chart (using ServletOutputStream to flush out the stream), and in jsp file, I have a code like that:
<form action="servlet_to_flush_stream">
<iframe name="f" src="" onreadystatechange="stateChanged()" style="display:none"></iframe>

function stateChanged()
   if (document.all['f'].readyState=="interactive")
        if(document.all['f'].src != "")
            // we need to call setInterval in a separated thread,
            // so it'll not be blocked by the save dialog.
                interval = setInterval(function()
                        self.opener = null;
                },1000); //// HERE I TRY TO CLOSE THE JSP PAGE EACH 1 second
            },1);///// HERE I set timeout is 1 msecond ??? but how can we know how much time we need to flush the stream

Accepted Solution

modulo earned 0 total points
ID: 14410120
PAQed with points refunded (50)

Community Support Moderator

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question