Jump to content

Perform Server push back to client


skliz4rel

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.