开发者

Ajax Push Engine (Comet) and persistent chat - how to implement?

开发者 https://www.devze.com 2023-01-22 10:50 出处:网络
We are developing an online real-time web browser game and we have chosen to use APE Server. We have an in-game chat system from our previous project and we would like to port it to APE. As we are a b

We are developing an online real-time web browser game and we have chosen to use APE Server. We have an in-game chat system from our previous project and we would like to port it to APE. As we are a bit new to APE we are not sure about which scenario would work better or maybe would not work at all.

Now the chat works the following way: -the chat has 4 rooms where users talk about some certain game aspect (trade, fight etc.) when user reloads the page completely, he/she gets the latest 30 messages form db (database) for the opened chat room -the chat is issuing periodic AJAX requests to see if there are new messages in any of the chat rooms, but the actual latest messages are downloaded only for the chat room which is currently open. To make things even more complicated, we have separated the chat into separate languages - users get messages only for the language which is in their preferences cookie. They can change it any time and then they'll get messages for the other language.

Now as we are moving to completely AJAX based system without page reloading at all, we will be automatically minimizing the requests to get the latest 30 messages form db.

But the hard part is - how to organize storing the messages in db and sending to the users through APE?

We have considered the following options: - user sends a message to PHP script, it goes to db, then PHP submits the message to the APE through inlinepush (according to docs, inlinepush supports only one channel, we are not sure how it will work then) and then APE is sending the message to all users (it seems, we need to store on the APE server also the user preferred language, so the message gets sent only to appropriate users); - user sends the message to APE Server, and APE server delivers it to the other users of the same language and also calls PHP script to store the message to db; - user sends the message to APE Server, and APE server delivers it to the other users of the same language and stores the message to db using APE's own Mysql abilities.

From the one hand, we prefer to store data through PHP because we have a pretty robust db access library and we would like to avoid porting it to APE and Javascript just to store chat messages (and also we have no experience with server-side JS). But if it will give some good advantages then of course we will use A开发者_开发百科PE's own Mysql.

Also we are worried, will APE be able to filter all users by their language and send the message only to appropriate users? How APE is dealing with cookies?

Also the subdomain-based channels in APE seem a bit awkward to set up, but we haven't found any better alternative yet.


Check this link:

http://www.ape-project.org

It seems to be an open source project that implements the AJAX PUSH ENGINE Concept.

They provided you the code(server side and client side). Though it seems to have no support for Windows that what I actually looking into but it may help you if you need it.

Though the answer seems to be of no use to the actual person who posted the question becuase it is a long time.


We ended up using node.js and Faye with a custom authentication, and it worked just fine. Faye is pretty lightweight and customizable, no hassles with complicated domain setup. It was also relatively easy to code our own SQL back-end through PHP.

Faye

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号