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.

Recommended Answers

All 7 Replies

can i use gcm for chat like fb ?

Member Avatar for diafol

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.

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 ?

Member Avatar for diafol

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.

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();

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.