Jump to content


Photo

Perform Server push back to client


  • Please log in to reply
3 replies to this topic

#1 skliz4rel

skliz4rel

    Member

  • Members
  • PipPip
  • 11 posts

Posted 03 February 2013 - 09:36 AM

Please I am developing a chat application. I need script to push back message from server db to client when users are chatting. I have been using pooling through ajax but it is running down my server each time multiple people connect to it.

I have tried the Ape framework. But I dont understand it. It is all written in C. please some one helpp !!.

I also tried socket but I am new and I thinking of browsers that dont yet support it. By the way I have gone very far in the project and dont know how to slot in socket into the codes.

#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,709 posts
  • LocationBonita, FL

Posted 03 February 2013 - 12:31 PM

Websockets would be the best method, and you can get decent support by using a library such as Socket.IO.

Otherwise you'll need to use either Long Polling, Short Polling or just page refreshing.  None of them are that great when it comes to efficiency.

Long Polling will tie up server threads/resources for each person connected while it waits for new data.
Short polling won't tie up server threads, but creates a lot of traffic by constantly connecting, eating bandwidth and processing time.
Page refreshing is basically like short polling but worse because you're regenerating the entire page rather than just passing message data.

Long polling can be made more efficient if you write your own server to handle the connections rather than route them through something like Apache.  Doing so properly can be a bit of a challenge though.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#3 Andy123

Andy123

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts
  • LocationDenmark

Posted 03 February 2013 - 04:09 PM

As you said, polling is not a good way to go if you start to get a bit of traffic. Web sockets would be your best bet I believe. It is true that there is a challenge with the browser support, but wouldn't it be acceptable to give the user a message that their browser is updated if it doesn't support it? There are surely other methods of doing this, some of which kicken described, but many of them are quite challenging to implement. Reading your post, I have the impression that you don't want to go for something highly complicated. I'd say that web sockets is the way to go. People with old browsers can simply choose to upgrade or to not use the chat. Supporting old browser versions is something that is going away very fast, so I would just forget about it but make sure that you present the users with a user friendly message (feature checking).
Blogging about PHP and other programming related subjects at CodingExplained.com.

#4 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 03 February 2013 - 05:46 PM

I'd probably set it up to try web sockets first, and if that wasn't available I'd fall back to short polling with AJAX.

There is actually quite a bit that can be done to cut down on the resource usage that short polling creates, but it does require fairly extensive knowledge about the tools you're using. You should be able to get the chat to support at least around a hundred simultaneous users, if you tweak it properly. Without it affecting the rest of the site, too much.
Keeping it simple.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com