Jump to content

Connect 2 users to a single Server


shreyaskudav

Recommended Posts

If two users are looking at the same webpage then they are almost certainly looking at the same server (or server cluster). The shared storage for all user inputs is the server database. For example if you had two users connect to the same webpage the database for that webpage could be used to pass messages between the users in a chat-room application.

Link to comment
Share on other sites

Foxy was making the point that nothing in a computer is actually simultaneous, and HTTP by itself is very limited.

 

The only issue is -- how quickly do you need to see the value that the other user sent?

  • Like 1
Link to comment
Share on other sites

Sorry..I am not that familiar to ajax! But the first thing I need is to know is,... how can I take 2 request from different users...!

Should I declare 2 objects of Httprequest or I should use it array of Httprequest??

Link to comment
Share on other sites

Each client performs any amount of HTTP requests. It's up to the server code to identify the client and create a relation between two different clients.

Link to comment
Share on other sites

Let's see... Sessions won't be necessary if you build it properly.

First you have a lobby screen: A user can choose to create a game or join an existing game. Each user should be uniquely identified. To do this, as soon as they visit the page for the first time PHP should send them the identifier which they'll send back on every request.

 

Once one user has created a game and another user has joined the game can begin. Every 5 seconds or so you send an AJAX request to see if the other player moved, if it's the current player's turn then it will only need to send a request when the player moves.

 

Once the game is over the server needs to make sure that both players have been notified of it before eliminating all the data.

 

It's not a simple task, really. There are lots of details to think of both on the client side and the server side.

  • Like 1
Link to comment
Share on other sites

Once one user has created a game and another user has joined the game can begin.

So if I am using Ajax! so I will be using xmlhttprequest objects!.. But should declare 2 objects.. 1 for each user! or array of httprequest??

Which will be better??

OR

Is it possible to use the same object for both the users???

Link to comment
Share on other sites

Each client is on a different page, in a completely different environment. The Javascript that is executing on one user's computer is a completely different program than the one running on another user's computer. You only need to program the interface for one user. It is the one interface that all the users visiting your page will use.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...