Android client-server logic for a multi-player game

| | August 5, 2015

I’m creating an android “quiz” app. The game can be played by two user in real-time. I’m creating game on server with this design:

//node js server
//new game request api
@game/request/new

var currentUser = req.user

var opponentUser = Lobby.findOpponent()

if(opponentUser == null) // send response he is in lobby
{
    res.send("lobby")
    Lobby.addWaiting(currentUser)
    //if he stays in lobby for 10 seconds
    //send a "leave lobby" request
}
else //send response he is matched with a user
{
    res.send("matched")
    createGame(currentUser, opponentUser)
}

In my createGame function I’m sending the separate game data to the these two user, using Google Cloud Messaging.

{
 sessionId: '',
 questions: [],
 me: {},
 opponent: {}
}

1- Is this approach for creating game is good ? So far I don’t a have problem but I’m not experienced.

2- How should I check if a user disconnected (incoming call, losing internet etc..) from the game session? I really don’t know.

Leave a Reply