Android Question Best approach online game playing (php server <=> android devices)

Toky Olivier

Active Member
Licensed User
Longtime User
Hello,
Can you tell me please the best approach to implement an online game playing? I have one server with php (for me, the most affordable) which plays as the game server (online players, receive and send message from one device to one or multiple devices,...). It's a simple board game but another devices can watch the game party.
I see some examples with MQTT and Firebase or B4J server but I would like to implement it with php only as It's what is available to me now.
What I did is:
- I implemented a rest api server with php on the server
- With android devices, I used okhttputils2 for the communication. Devices send command to the server and wich interprets the command and sends the response immediately to the sender or store some information in the database and wait for another device command before putting some response in the database for the initial sender. The initial send checks regularly that response via http get/post and acts depending the response.
I think it's not a good approach as many datas are sent from the device to the server just for checking some availaibility of response on the database. And also, I didnvt check battery power consumption.
With sockets and only 2 devices, it's okay and easy to implement but with multiple devices and a php server, I didn't find how to do it.
Should I use MQTT for this?
Thank you
 

Toky Olivier

Active Member
Licensed User
Longtime User
Seeing posts and tutorials in the forum. It seems that the solution is Firebase realtimedatabase. Never used it but I'll try.
 
Upvote 0

Toky Olivier

Active Member
Licensed User
Longtime User
MQTT would be a good solution I would think. Players in the same game would subscribe to the same channel and can communicate quickly with each other.
Yes but we don't have MQTT broker service payable in Madagascar and free plan available online are very limited as far as I know. Do you know any free plan usable of MQTT broker service please?
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Upvote 0

Toky Olivier

Active Member
Licensed User
Longtime User
@Toky Olivier is probably using a shared server solution which means he does not have access to any desktops, ftp, emailing, hosting just a basic hosting package I presume, no VPS...
Yes. I use shared server solution, no VPS. But yes, client side ftp, emailing, etc are available. No need here I think. But the node.js selector is active. I didn't test yet if I can use socket.io and the b4a library available in the forum.
 
Upvote 0

Biswajit

Active Member
Licensed User
Longtime User
One thing you can try using firebase messaging,
  1. Share your token before the game starts.
  2. On player action send a request to PHP server with opponent token and data.
  3. From PHP server fire a firebase notification to that token.
  4. On receiving the data in the opponent device parse the data and use it as you want.
  5. Do the same on the opponent side (2-4).
 
Upvote 0

Toky Olivier

Active Member
Licensed User
Longtime User
One thing you can try using firebase messaging,
  1. Share your token before the game starts.
  2. On player action send a request to PHP server with opponent token and data.
  3. From PHP server fire a firebase notification to that token.
  4. On receiving the data in the opponent device parse the data and use it as you want.
  5. Do the same on the opponent side (2-4).
I like your idea. I'll try it. I'm sure it'll work. Thank you.
 
Upvote 0
Top