1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Server to browser communications

Discussion in 'JavaScript' started by astrazone, Aug 10, 2011.

  1. #1
    I was wondering how to make the server send events to the browser(client) when database is updated?
    Google and facebook have it with their chat systems but I couldn't really understand how they work because after the page was sent, the connection is terminated.

    So how can I set up something that will receive data on database update?

    Thanks in advance,
    Astrazone
     
    astrazone, Aug 10, 2011 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The client may be polling the server at regular intervals and checking for new data.
     
    Cash Nebula, Aug 10, 2011 IP
  3. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #3
    Lets think about it for a sec... Facebook has 750,000,000 users and 50% are active all the time, so its 375,000,000 users that need to send a request about every second no server in the world can handle it, 22500000000 requests per minute.
    And I read about it somewhere that they are using something that can receive data from the server like this http://dev.w3.org/html5/eventsource/.
    Did anyone ever used it? because I cant understand what do I need to use it.

    Update : I also found this, but I have no idea how to set it up and what do I need for it. looking for good advice about all of this
     
    astrazone, Aug 10, 2011 IP
  4. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #4

    Yes, your right that can't be handled by a single server but Facebook has multiple servers, each server handle requests on a certain number of users. That's why it can handle those millions of users.

    On to your first question, checking database statuses like in chat are constantly checked with a certain interval. Sometimes this checking is done using Flash instead of Javascript intervals because it takes a big load to the browser. Flash will then call a certain javascript function to tell the browser that there's an update in the chat.
     
    JohnnySchultz, Aug 11, 2011 IP
  5. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #5
    I think that I am more interested in something like WebSync or CometD.
    But I dont know how to install CometD and the instructions aren't helping...
     
    astrazone, Aug 11, 2011 IP
  6. Farbyte

    Farbyte Member

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    The only way to do this from server side is to allow connections from the server to the client and have a port listening on the client.
    This would require opening firewalls etc.
     
    Farbyte, Aug 11, 2011 IP
  7. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #7
    I agree with you Farbyte, but I think that a server application would be faster than simply doing an AJAX request every second. I just need a simple guide on how to set it up on my server/XAMPP.
     
    astrazone, Aug 11, 2011 IP