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

  • SEARCH
  • Home
  • 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 6946113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:31:23+00:00 2026-05-27T13:31:23+00:00

I have a simple comet server in written in Twisted. It prints out time

  • 0

I have a simple comet server in written in Twisted. It prints out time stamps. I also have a small static webserver running on the same port. The javascript on the page served tries to update the page by appending the timestamps from the comet server.

But nothing is displayed from the comet server. Using the developer tools in Chromium, I can see that a long connection is opened. But the connection times out and nothing is appended to the page. Why doesn’t it work?

Here’s a self-contained example:

from twisted.internet import reactor
from twisted.internet import task
from twisted.web import server
from twisted.web.server import Site
from twisted.web.resource import Resource
import time

class ClockPage(Resource):
    isLeaf = True
    def __init__(self):
        self.presence=[]
        loopingCall = task.LoopingCall(self._print_time)
        loopingCall.start(1, False)
        Resource.__init__(self)

    def render_GET(self, request):
    # The browser won't display any output until it's gotten a minimum
    # number of bytes from the server or something. Hence, junk divs.
        request.write('''<div class="11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"></div><div class="111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111187348937284789374872387847847811111111111111723872187383738271893789217387389737389711111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"></div>''')
        request.write('<b>%s</b><br>' % (time.ctime(),))
        self.presence.append(request)
        return server.NOT_DONE_YET

    def _print_time(self):
        for p in self.presence:
            p.write('<b>%s</b><br>' % (time.ctime(),))

class UpdatePage(Resource):
    def render_GET(self, request):
        return """
        <!doctype html>
<html>
    <head>
        <title>Metastatus</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js";></script>

        <script type="text/javascript">
function addentry(type, msg) {
    "use strict";
    if (type === "new" && msg !== "") {
        $("#entries").prepend(
            "<li>" + msg + "</li>"
        );
    }
}

function waitForMsg() {
    "use strict";
    $.ajax({
        type: "GET",
        url: "http://localhost:8080/clock",

        async: true, /* If set to non-async, browser shows page as "Loading.."*/
        cache: false,
        timeout: 50000, /* Timeout in ms */

        success: function (data) { /* called when request to barge.php completes */
            addentry("new", data); /* Add response to a .msg div (with the "new" class)*/
            setTimeout(
                waitForMsg(), /* Request next message */
                1000 /* ..after 1 seconds */
            );
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            addentry("error", textStatus + " (" + errorThrown + ")");
            setTimeout(
                waitForMsg(), /* Try again after.. */
                "15000"
            ); /* milliseconds (15seconds) */
        }
    });
}

$(document).ready(function () {
    "use strict";
    waitForMsg(); /* Start the inital request */
});
  </script>
   </head>
    <body>
      <h1>Example</h1>
      <ul id="entries"></ul>
    </body>
</html>"""

if __name__ == '__main__':
    root = Resource()
    root.putChild('', UpdatePage())
    root.putChild('clock', ClockPage())
    factory = Site(root)
    reactor.listenTCP(8080, factory)
    reactor.run()
  • 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-27T13:31:24+00:00Added an answer on May 27, 2026 at 1:31 pm

    You can’t rely on getting response data in JavaScript until the response is fully delivered to the client. This behavior varies from browser to browser, so you will see it work as you want sometimes, and not work at all other times.

    You also can’t rely on connections remaining open indefinitely, largely due to HTTP proxies between the browser and your server.

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

Sidebar

Related Questions

I have the following: My webserver running on twisted My comet server, aka orbited
I have written a simple server - client program with Swing interface using singleton
I have simple Perl/CGI scripts based web server which is mainly used to display
I have a simple comet chat. JavaScript send ajax request with long polling. When
I just have a simple ASP Table seen here: <asp:Table ID=tblCategories runat=server CssClass=oneColTable padded-table
I have a very simple application in c# it has a Microsoft SQL Server
I currently have a very simple web application written in Django, and I would
this is more theoretical question. I have written simple chat with my friend. We
I have a simple TCP server that communicates with some devices via GPRS. It
At the moment, I have a simple app that Ajax's to a server, gets

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.