Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8179531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:01:14+00:00 2026-06-07T00:01:14+00:00

I just learned about comet pattern(Long polling) and very curious to implement a simple

  • 0

I just learned about comet pattern(Long polling) and very curious to implement a simple example with Tomcat6 as container.
What i am trying to do here is – I am going to call a servlet that generates a random number between 1 and 20 and based on that random number it should waits that number of seconds before responding to client.

For Example : if generated random number is 10 , then the servlet should wait 10 seconds before it send response.

Here is my servlet that implements CometProcessor

public class RandomNumberGenerator extends HttpServlet implements CometProcessor {

doPost method :

        PrintWriter out =response.getWriter();
        Random r = new Random();
        int randomInt = r.nextInt(20) + 1;
        out.print(randomInt);
        out.flush();
        out.close();

Now, as i implemented CometProcessor I’ve got an event method :

@Override
    public void event(CometEvent event) throws IOException, ServletException {

    }

What i can’t figure out is that, what Iv’e to do with this event method to do what i want.

What i know here is, their will be some events i can handle inside this method like : BRGIN,READ,END,ERROR

Should i use events like this ?

if (event.getEventType() == CometEvent.EventType.BEGIN) {
    event.setTimeout(numberOfSecondToWait);
}

I am totally confused as this tutorial seem a bit complex to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:01:14+00:00Added an answer on June 7, 2026 at 12:01 am

    I recently wrote a blog post on WebSockets and Comet and asked the inventor of ‘Comet’ to provide his opinion.

    In summary, Alex said WebSockets replace Comet.

    So, although people are still using Comet it will ultimately be replaced with WebSockets since they were specifically created to solve a problem that Comet solutions hacked around.

    I’d recommend you shift your focus to WebSockets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just learned about jquery's .makeArray and I am trying to use JSON.stringify to
I just learned about the existence of the PRG pattern, and I'm wondering if
I just learned about the Template Method pattern in this answer to a question
I've just learned about the CRTP Pattern and am looking for the original work.
I just learned about ThreadLocal this morning. I read that it should always be
So I just learned about preg_match in PHP the other day and now i'm
I've just recently learned about friend class concept in C++ (I've googled around for
I just posted this question and learned about <see cref=> , however when i
I just learned about list comprehension, which is a great fast way to get
I just learned about the XmlSerializer class in .Net. Before I had always parsed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.