473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Turn based web game in PHP - communication issue

Hi all!

I am working on a turn based web game in PHP5.

This is pretty simple game, a kind of board game: two people join a "session" and they play until one of them wins.

My problem in nutshell:

* User A and User B play a game.

* User A finished his turn
* Request will be sent to the server to perform necessary operations.
* Now it is time for User B to move..

But how could I notify User B about this?

I mean, now the server has to communicate with the other user, the one that is inactive, not the one that initiated the request.

I know that this could be implemented using some kind of periodic AJAX call that checks whether or not the opponent finished his turn etc, but such a thing generates a huge number of requests.

Isn't there a better way to solve this?

I'm thinking of something like this:

* User A's turn ends
* Server saves his score
* Server contacts User B
* User B's turn gets started.

Is this possible using PHP? Should I use comet style AJAX? Or is there a better way to do this?

Any help would be appreciated!

Thanks in advance!
Aug 14 '10 #1
2 2280
Atli
5,058 Expert 4TB
The current web technologies offer no methods for the server to initiate communications with the client. The client has to send a request to the server. HTML5 will remedy this with the WebSockets interface though.

However, there are ways to trick the browser into maintaining an open connection to the server, allowing the server to send JavaScript triggers to the client. There are several methods you can use. See Comet on Wikipedia. I'd check out the part about "long polling". I suspect it might work out best for your purposes.
Aug 15 '10 #2
How do you see a user when he/she logs out from yahoo messenger?

Explore the same way.
Aug 24 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
2
by: Flavio | last post by:
Hi, I'm used in MS Access on Doing Queries based on Queries. Now that I'm dealling a lot with large ammount of data I think this procedure with an SQL Server back-end is falling a little bit...
0
by: Jim | last post by:
I am having some trouble with user controls and would appreciate any input / advice on where to go with this... :) 1. The first problem, and perhaps the root of the others, is that I have...
3
by: John Dolan | last post by:
Hi all, I need some help here. I have an ActiveX object that requires me to pass in an array that is 1-based (as opposed to the normal 0-based index). Unfortunately the author of the ActiveX...
1
by: Antimon | last post by:
Hi, I am working on a browser based space simulation game. I think about two different architectures but i cannot decide, First one is to use and rdbms to store persistent world data. But i...
1
by: esparkman | last post by:
Hey guys, Kinda stuck in a rut on this one. I'm designing a online stats tracking web app for the game battlefield 2. I want to display the players rank represented by an image. That is in turn...
2
by: jj19902003 | last post by:
i like to play a game called runescape, http://www.runescape.com and i used to be able to play it on the same computer i am on now. but now all of a sudden my internet slows way down to the point of...
31
by: jj19902003 | last post by:
i like to play a game called runescape, http://www.runescape.com and i used to be able to play it on the same computer i am on now. but now all of a sudden my internet slows way down to the point of...
5
by: AeonOfTime | last post by:
Let's assume a web application (in this case a browser-based game) with a custom HTTP server built on PHP, and a client also built on PHP. The client uses the server to access and change data. Even...
1
by: cousinoer5 | last post by:
I'm trying to implement a shop in my game, right now I can buy anything in the shop and it works perfectly, but I can't sell anything because I get an error I can't figure out. Here's the relevent...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.