3 Replies Latest reply on Feb 22, 2013 11:26 PM by kiran kumar

    jboss 5.1.0.GA server push is working only on local PC,Not working if i access it from another PC with in the network.

    kiran kumar Newbie

      Hi,

            I had implemented the comet serverpush for one of the module in my project, using jboss 5.1.0.GA+ jboss-web-2.1.9.GA+ org.apache.coyote.http11.Http11AprProtocol+Ajax.

            It works fine in the local system. Whenever the new data comes to the server, server pushes the data to the Client.

       

           But when i try to access the same application from my coleagues system in the company, I am able to access the entire application. but server push is not working.And i dont find any error on the console/Log.

            I really dont understand what went wrong. Is it because of the Proxy/Firewall. If so how can i make it accessible.

       

           Please help me on this.

       

      Regards,

      Kiran.

        • 1. Re: jboss 5.1.0.GA server push is working only on local PC,Not working if i access it from another PC with in the network.
          Jean-Frederic Clere Master

          It is probably a issue in your application like not flush data or a direct broken. If you can acces to the rest of the application that I think it had nothing to do with the firewall.

          You should track down where the problem is a send a piece of your code so it is possible to see what is wrong.

          1 of 1 people found this helpful
          • 2. Re: jboss 5.1.0.GA server push is working only on local PC,Not working if i access it from another PC with in the network.
            kiran kumar Newbie

            Hi Jean Frederic,

                                        Server is flushing the data when i access the application where it had been deployed. I ran the application in debug mode by keeping the debug point at public void event(HttpEvent event) method of the EventPush class. The following class is not being initiated when i accessed from another PC but in the same network.

             

            public class EventPush extends HttpServlet implements org.jboss.servlet.http.HttpEventServlet{

                         private ArrayList<HttpServletResponse> connections = new ArrayList<HttpServletResponse>();

                          protected EventDataSender eventDataSender = null;

             

                          public void init() throws ServletException {

                                    eventDataSender= new EventDataSender();

                              Thread messageSenderThread =new Thread(eventDataSender, "Sender[" + getServletContext().getContextPath() + "]");

                              messageSenderThread.setDaemon(true);

                              messageSenderThread.start();

                          }

             

             

                          public void destroy() {

                              connections.clear();

                              eventDataSender.stop();

                              eventDataSender = null;

                          }

             

             

                          /**

                           * Process the given event.

                           *

                           * @param event The event that will be processed

                           * @throws IOException

                           * @throws ServletException

                           */

                          public void event(HttpEvent event)

                              throws IOException, ServletException {

                              HttpServletRequest request = event.getHttpServletRequest();

                              HttpServletResponse response = event.getHttpServletResponse();

                              event.setTimeout(60000);

                              switch (event.getType()) {

                              case BEGIN:

                                  System.out.println("Begin for session: " + request.getSession(true).getId());

                              //      PrintWriter writer = response.getWriter();

                              //    writer.println("<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">");

                              //  writer.println("<head><title>JSP Chat</title></head><body bgcolor=\"#FFFFFF\">");

                              //    writer.flush();

                                  synchronized(connections) {

                                      connections.add(response);

                                      eventDataSender.addConnection(response);

                                  }

                                  break;

                              case ERROR:

                                        System.out.println("Error for session: " + request.getSession(true).getId());

                                  synchronized(connections) {

                                      connections.remove(response);

                                      eventDataSender.removeConnection(response);

                                  }

                                  event.close();

                                  break;

                              case END:

                                        System.out.println("End for session: " + request.getSession(true).getId());

                                  synchronized(connections) {

                                      connections.remove(response);

                                      eventDataSender.removeConnection(response);

                                  }

                                  //PrintWriter writer = response.getWriter();

                                  //writer.println("</body></html>");

                                  event.close();

                                  break;

                              case READ:

                                  InputStream is = request.getInputStream();

                                  byte[] buf = new byte[512];

                                  while (is.available() > 0) {

                                      int n = is.read(buf); //can throw an IOException

                                      if (n > 0) {

                                                System.out.println("Read " + n + " bytes: " + new String(buf, 0, n)+ " for session: " + request.getSession(true).getId());

                                      } else {

                                          //error(event, request, response);

                                          return;

                                      }

                                  }

                              case TIMEOUT:

                                        System.out.println("timeout occured for event");

                                        event.close();

                              }

                          }

            }

            ==========

             

              import java.io.IOException;

            import java.io.PrintWriter;

            import java.util.ArrayList;

             

             

            import javax.servlet.http.HttpServletResponse;

             

             

            public class EventDataSender implements Runnable {

                      protected boolean running = true;

                      public static ArrayList<String> messages = new ArrayList<String>();

                      protected ArrayList<HttpServletResponse> connections = new ArrayList<HttpServletResponse>();

                      public EventDataSender() {

                      }

             

             

                      public void stop() {

                                running = false;

                      }

             

             

                      /**

                       * Add message for sending.

                       */

                      public void send( String message) {

                                synchronized (messages) {

                                          messages.add(message);

                                          messages.notify();

                                }

                      }

                       public synchronized void addConnection(HttpServletResponse connection){

                                 connections.add(connection);

                              notify();

                          }

                       public synchronized void removeConnection(HttpServletResponse connection){

                                 connections.remove(connection);

                              notify();

                          }

             

                      public void run() {

             

             

                                while (running) {

             

             

                                          if (messages.size() == 0) {

                                                    try {

                                                              synchronized (messages) {

                                                                        messages.wait();

                                                              }

                                                    } catch (InterruptedException e) {

                                                              // Ignore

                                                    }

                                          }

             

             

                                          synchronized (connections) {

                                                    String[] pendingMessages = null;

                                                    synchronized (messages) {

                                                              pendingMessages = messages.toArray(new String[0]);

                                                              messages.clear();

                                                    }

                                                    // Send any pending message on all the open connections

                                                    // If a connection backlogs, there will be an exception

                                                    for (int i = 0; i < connections.size(); i++) {

                                                              try {

                                                                        PrintWriter writer = connections.get(i).getWriter();

                                                                        for (int j = 0; j < pendingMessages.length; j++) {

                                                                                  writer.print(pendingMessages[j]);

                                                                        }

                                                                        writer.flush();

                                                              //          writer.close();

                                                              } catch (IOException e) {

                                                                        System.out.println("exception "+e);

                                                              }

                                                    }

                                          }

             

             

                                }

             

             

                      }

            }

            • 3. Re: jboss 5.1.0.GA server push is working only on local PC,Not working if i access it from another PC with in the network.
              kiran kumar Newbie

              Hi Jean Frederic Clere,

                                                Thanks for your respnose, actually its my mistake.

                                               In the JSP where the serverpush is called i had mentioned the URL as localhost,instead of the domain name so thats why it works only on local PC.Now the problem is solved.