Hi,
I'm pretty sure that the answer is 1A. As long as your script deals well with
the different connections there should be no problems. As far as I am aware, a
single listening socket may have multiple 'connections' and you'll probably
find lots of code for storing each connection in an array, and reading and
sending data to each seperate connection.
The rest of it (session management, multiple games etc) I would suggest you
use the same script, and code your script to deal with these things. I suggest
a very simple scheme whereby the data packets are structured and can be used
for many games:
packet_type - game_code - player_id - payload
The packet type could be:
A - I want to start playing a game. I dont have an opponent.
B - I am playing a game
C - I am sending a command (stop server, disconnect me, etc)
game_code could be:
A - Game 1
B - Game 2
player_id could be a string of set length (e.g. 4 numerals) asigned by the PHP
script when a connection is made. This is sent with every subsequent request
to identify the player
payload is your game data (players position etc).
An example data packet:
AB0001ffa0
Note that the aim is to get the data packet as small as possible to reduce
network traffic. Another thing you have to look at is whether you can use UPD,
or whether communication has to be TCP. TCP is the usual method of sending
traffic over the internet. WHat happens with TCP is that a packet is sent and
then the socket WAITS untill it receives a response saying "yip, I got the
packet ok" and then it sends the next one. You can see that if there is a lot
of network traffic that the ball in pong would jerk around a lot and sit on the
spot sometimes.
A better method is to use UPD, which just sends the packet, and doesnt care if
it makes it or not. If the socket is ready to send another packet before a
response comes back its ok, because the socket isnt waiting.
Another thing thats good to do (are you still with me :)) is called
dead-reckoning. Without dead reckoning you might move your pong ball to the
location that is given in the data packet. This means that the ball sits at
this location until it gets the next packet. Dead reckoning means to continue
moving the ball where the game calculates it should be, and then update the
balls position as the packets come in.
Anyway, theres heaps of things that you should look into. Best to give me an
email: peter at pixelthis dot co dot nz
A very good resource on network gaming in general is gamasutra
(
www.gamasutra.com) you'll need to sign up (free) to get access to the
articles, but they are written by the gaming guru's themselves :)
Cheers,
Pea