2014-11-22 16:23
浏览 19

如何在AJAX XML的同时重定向两个用户?

I have two logged in users, with "id" and "id2". Both users are on index page, but there are also other users.

If one of the users click the button, he and the other user (with id2) to be redirected to another page. How am I supposed to redirect only these two users at the same time.

function redirect() {
     //redirect only user with id and id2

图片转代码服务由CSDN问答提供 功能建议

我有两个登录用户,“id”和“id2”。 两个用户都在索引页面上,但也有其他用户。

如果其中一个用户单击该按钮,则他和另一个用户(具有id2)将被重定向到另一个页面。 我应该如何同时仅重定向这两个用户。

  function redirect(){
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doufan2541 2014-11-22 16:37

    This depends on how complicated you plan on making your game. Generally for online games, the state is stored on the server, and the clients are just viewers with varying levels of smartness.

    Assuming you have somethink like a 'find game' button, the users would send a request to the server and the server would redirect to the 'room' URL for a game that needs more people, or a new room would be created so other people could join this user.

    Once people start joining the room, they would need to basically wait for the room owner to start the same. There are a bunch of ways to do this. In your case, the simplest is to have each client keep sending requests to the server to see if the game has started or not, and if so, redirect to the new URL. The clients could also use websockets or long polling to accomplish this if you wanted potentially better reaction times.

    So basically, you aren't "redirecting two users at the same time", you are changing the state of the game from "waiting for people" to "started" or something like that, and then when each user seems that the game is started, then server would redirect them.

    Basically, I'd think of the game as two people talking to a server separately. The fact that they are playing the same game is reflected in the state of the game, but they aren't usually communicating directly with each other.

    点赞 评论
  • doujingtang6580 2014-11-22 19:18

    This is far easier in NodeJS, you can use to send a notification to the browser to make them change room instead of having to constantly poll a server.

    点赞 评论

相关推荐 更多相似问题