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 6143705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:33:20+00:00 2026-05-23T18:33:20+00:00

I am writing a Web chat application. It uses a long polling mechanism. Basically

  • 0

I am writing a Web chat application. It uses a long polling mechanism. Basically you send a request to the server, and the server holds it until there is data to send back. Then it responds, and then the client sends another request to the server. And the cycle repeats.

However, there is a problem – I have no error checking in place. What if the connection drops? Let’s say I’m chatting with a friend and then my Wifi drops. Internet’s down and let’s say it goes back up a minute later. But then the long-polling mechanism has already died and with no polling, I have to refresh the page.

How can I implement an error checking mechanism to solve the problem of unsuccessful or dropped network connections? I am using jQuery to facilitate the Ajax requests if that helps.

*EDIT: Here is my JS code for the polling mechanism: *

// Polls the server for more data, basically a regular encrypted request
Minte.Network.poll = function()
{
    // If client is not connected, do not send poll requests
    if (!Minte.Client.connected)
        return; 

    Minte.Network.request({ "action" : "poll"}, function(data) {

        // If a client has disconnected and a poll returns afterwards, do not process it
        if (!Minte.Client.connected)
            return;

        Minte.Network.lastPoll = Minte.clock.getTime(); 
        Minte.Processor.process(data); 
        Minte.Network.poll(); 
    }); 
}; 


// Send a regular, routine encrypted request
Minte.Network.request = function(data, callback) 
{

    $.post(SERVER_URI, data, function(data, textStatus, jqXHR) {
        data = JSON.parse(data); 
        callback(data); 
    }); 
}; 
  • 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-05-23T18:33:21+00:00Added an answer on May 23, 2026 at 6:33 pm

    First off, you can hook the error handling of the ajax call. If it fails, you should eventually get an error condition back. Since I haven’t seen this defined anywhere, you’d probably have to work out a way to test how all the different browsers respond when the connection is lost in different ways to see if this is something you could use exclusively. In any case, it won’t hurt to hook the ajax failure response. You will likely also want to implement your own timeout so that if you haven’t heard back from the server in xx time, then there must be some sort of problem.

    Second off, if you want quicker feedback and more likely to be consistent even in different browsers, then you can have your server return a heartbeat. So, ever xx seconds of inactivity, your server would return a heartbeat response. The client would wait, xx + yy seconds (yy is some extra to allow for roundtrip time and any slight lag in the server response) and if it didn’t receive either an actual datagram back from the server or a heartbeat response, then it would assume the connection has died. If it receives a heartbeat, it just makes another request again. You can set the heartbeat to whatever interval you want, though obviously short times are more taxing on the server infrastructure.

    FYI, jQuery has a global ajax error handler described here: http://api.jquery.com/ajaxError#callback and the jQuery ajax call itself allow you to specify a timeout and an error handler.

    In pseudo code:

    $.ajax({
       url: 'xxxx',
       success: function(data, textStatus, jqXHR) {
          if (data is heartbeat) start a new ajax connection to ask again
          if (data has returned data in it) process it
       };
       error: function(jqXHR, textStatus, errorThrown) {
           some sort of connection error has happened
       };
       timeout: 2 * 60 * 1000;   // 2 minutes
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a web application which uses forms and PHP $_POST data (so
I writing a web site that uses Active Directory to validate users. I don't
I am writing a web application that requires user interaction via email. I'm curious
I am writing a web server in Java and I want it to support
I'm writing a web application that decodes Morse Code that is tapped in using
I am writing a Web Application in ASP.NET using C#. Whenever I run it,
I am writing a web application deployment verification tool and I need to check
Several frameworks for writing web-based desktop-like applications have recently appeared. E.g. SproutCore and Cappuccino
I'm writing a web page in ASP.NET. I have some JavaScript code, and I
I'm writing a web service, and I want to return the data as XHTML.

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.