0

Hello Guys,
How can i check if it happend new events in server in real time without refreshing the page with js? I dont want to use node.js or ajax or html5 SSEs.

2
Contributors
7
Replies
26
Views
1 Year
Discussion Span
Last Post by phoenix254
1

Not sure about that - from what I gathered, it's more for notification. Never used it myself. You didn't actually mention chat in your OP. Is this what you actually want? If so, I would suggest sockets.

0

is sockets are good scale for server ?
and there are a bit hard to learn or arnt they ?
can u tell me write me ur own comet example ?

1

is sockets are good scale for server ?

SHould be ok

and there are a bit hard to learn or arnt they ?

Can be set up in a few hours after testing I would imagine

can u tell me write me ur own comet example ?

You need a comet server for this. There are online examples like the APE project. Not really my thing.

0

how would be this ?

var Comet = Class.create();
Comet.prototype = {timestamp: 0,
url: './backend.php',
  noerror: true,
  initialize: function() { },

  connect: function()
  {
    this.ajax = new Ajax.Request(this.url, {
      method: 'get',
      parameters: { 'timestamp' : this.timestamp },
      onSuccess: function(transport) {
        // handle the server response
        var responsed = transport.responseText.evalJSON();
        this.comet.timestamp = responsed['timestamp'];
        this.comet.handleResponse(responsed);
        this.comet.noerror = true;
      },
      onComplete: function(transport) {
        // send a new ajax request when this request is finished
        if (!this.comet.noerror)
          // if a connection problem occurs, try to reconnect each 5 seconds
          setTimeout(function(){ comet.connect() }, 5000); 
        else
          this.comet.connect();
        this.comet.noerror = false;
      }
    });
    this.ajax.comet = this;
  },

  disconnect: function()
  {
  },

  handleResponse: function(response)
  {
    $('content').innerHTML += '<div>' + response['msg'] + '</div>';
  },
  error : function(XMLHttpRequest, textstatus, error) { 
                    alert(error);
},

  doRequest: function(request)
  {
    new Ajax.Request(this.url, {
      method: 'get',
      parameters: { 'msg' : request }
    });
  }
}
var comet = new Comet();
comet.connect();
0

facebook uses comet teachnique and i dont think so they have or need comet server or dont they ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.