With Tomcat 3, I can flush the response's output buffer and the client will
receive the any data in the buffer.  With Tomcat 4, the only time the client
receives the data is when the servlet closes the response output and exits
from the doGet/doPost methods.  Does anyone know why this is the case?
Please see the code below.

Chester

============================================================================
=====
package test;

import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class TestServlet extends HttpServlet
{
        public static void main(String[] args) throws IOException {
                ObjectInputStream objin = null;
                
                try {
                        URL url = null;
                        
                        if (args.length > 0) {
                                System.out.println( ">>> TestServlet.main():
opening url=" + args[0] );
                                url = new URL(args[0]);
                        }
                        else
                                url = new
URL("http://localhost/test/servlet/TestServlet";);
                        
                        URLConnection con = url.openConnection();
                        
                        // prepare for both input and output
                        con.setDoInput(true);
                        con.setDoOutput(true);
                        
                        // turn off caching
                        con.setUseCaches(false);
                        
                        con.setRequestProperty("Content-Type",
"application/x-java-serialized-object");
                                
                        // write the serialized object as post data
                        ObjectOutputStream out = new
ObjectOutputStream(con.getOutputStream());
                        
                        out.writeObject("Anything");
                        
                        out.flush();
                        out.close();
                        
                        System.out.println( "Creating Object input stream"
);
                        objin = new ObjectInputStream(con.getInputStream());
                        System.out.println( "Got object input stream..." );
                        
                        Object event = null;
                        
                        while (true) {
                                if (event != null)
                                        System.out.println( ">>>
TestServlet.main(): received event=" + event );
                                        
                                System.out.println( ">>> TestServlet.main():
about to read object..." );
                                event = objin.readObject();
                                System.out.println( ">>> TestServlet.main():
finished reading object!" );
                        }
                }
                catch (Exception ex) {
                        ex.printStackTrace();
                }
                finally {
                        if (objin != null)
                                objin.close();
                }
        }
        
         /**
         * Handle the GET and HEAD methods by building a simple web page.
         * HEAD is just like GET, except that the server returns only the
         * headers (including content length) not the body we write.
         */
        public void doGet (     HttpServletRequest      request,
HttpServletResponse response )
                throws ServletException, IOException
        {
                doPost(request, response);
        }       

        public void doPost (    HttpServletRequest      request,
HttpServletResponse response )
                throws ServletException, IOException
        {
                BufferedOutputStream bout = new
BufferedOutputStream(response.getOutputStream());
                ObjectOutputStream objout = new ObjectOutputStream(bout);
                
                int i=0;
                
                while (true) {
                        try {
                                String event = "Server message " + ++i;
                                
                                System.out.println( ">>> TestServlet:
writing event=" + event );
                                objout.writeObject(event);
                                
                                objout.flush();
                                
                                Thread.sleep(500);
                        }
                        catch (Exception ex) {
                                System.out.println( ">>> doPost: " +
ex.getMessage() );
                                break;
                        }
                }

                objout.close();
                System.out.println( ">>> TestServlet exiting..." );
        }
}

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to