shreyaskudav Posted May 7, 2014 Share Posted May 7, 2014 How can I connect 2 users to access a single server, which would be a PHP code or an algorithm. I think it should be related to AJAX or Javascript! But Don't know what exactly How should I implement it! Link to comment Share on other sites More sharing options...
es131245 Posted May 7, 2014 Share Posted May 7, 2014 JS load throught HTTP server which can handle much more that 2 users. That exacly do you want? Limit access or a load page? Link to comment Share on other sites More sharing options...
shreyaskudav Posted May 7, 2014 Author Share Posted May 7, 2014 Sorry! i am not that familiar with ajax! so i don't know whats limit access and load page! But I want multiple pair of users to get access to the same server at the same time. Link to comment Share on other sites More sharing options...
davej Posted May 7, 2014 Share Posted May 7, 2014 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 More sharing options...
shreyaskudav Posted May 12, 2014 Author Share Posted May 12, 2014 I want to pass 2 values (integer type) from 2 different users at the same times... and process the result back to both the user.!! and this will go on... till a certain condition is satisfied! Link to comment Share on other sites More sharing options...
Ingolme Posted May 12, 2014 Share Posted May 12, 2014 HTTP doesn't take simultaneous connections into account. Link to comment Share on other sites More sharing options...
davej Posted May 12, 2014 Share Posted May 12, 2014 Like two people playing tic-tack-toe or battleship or rock-paper-scissors? Link to comment Share on other sites More sharing options...
shreyaskudav Posted May 12, 2014 Author Share Posted May 12, 2014 (edited) Yup! davej! exactly!! If http do not support it?? what should I use?? And also tic tac toe is usually a flash based..! mine is Browser Based Game.. ! Edited May 12, 2014 by shreyaskudav Link to comment Share on other sites More sharing options...
davej Posted May 12, 2014 Share Posted May 12, 2014 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? 1 Link to comment Share on other sites More sharing options...
shreyaskudav Posted May 12, 2014 Author Share Posted May 12, 2014 not more then 10 secs..! users are usually impatient..and horribly in the case of a game!! Link to comment Share on other sites More sharing options...
davej Posted May 12, 2014 Share Posted May 12, 2014 I don't think that would be difficult. You could have Ajax fire off a request for an update every five seconds. Link to comment Share on other sites More sharing options...
shreyaskudav Posted May 12, 2014 Author Share Posted May 12, 2014 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 More sharing options...
Ingolme Posted May 12, 2014 Share Posted May 12, 2014 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 More sharing options...
shreyaskudav Posted May 12, 2014 Author Share Posted May 12, 2014 Yes... thats what I tried to understnd!! but was not able!! Should I use sessions?? for it??if yes!! can u tell me the basic logic of it?? Link to comment Share on other sites More sharing options...
Ingolme Posted May 12, 2014 Share Posted May 12, 2014 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. 1 Link to comment Share on other sites More sharing options...
shreyaskudav Posted May 12, 2014 Author Share Posted May 12, 2014 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 More sharing options...
Ingolme Posted May 12, 2014 Share Posted May 12, 2014 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. 1 Link to comment Share on other sites More sharing options...
shreyaskudav Posted May 12, 2014 Author Share Posted May 12, 2014 Ohkk.. I will try with some simple mathematical calculation..so to check whether its taking ips and displaying ops or not!.. Thnks.. anyways... Foxy and Davej! Link to comment Share on other sites More sharing options...
davej Posted May 12, 2014 Share Posted May 12, 2014 See... http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_database Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now