Unity "Build a Town" Game - General DIrection Advice (Sockets vs GET/POST)

I need some general direction as to what will work and what will not.

If you have ever played Simpsons Tapped Out or Clash of Clans, you basically build a town. You select a building, you place it on the map, and your building takes X minutes to build.

Now, a few questions:

1)Is using PHP/MySQL + WWW/WWWForm (GET/POST) viable for this sort of game?
If so, then should I just load the information at the start and show timers based on internal local timers?
OR
Should i be constantly polling with callbacks?

  1. Would a TCP/IP Socket based approach be better suited (Im thinking yes)?
    If so, would you recommend using C# Console Application to run as my TCPListener and have my Unity Application Connect to and send/recieve information constantly? Id assume this would also use some sort of polling interval but I think a TCP/IP Connection with an active state would require less overhead than PHP/MYSQL with POST request implementations.

Im very well versed in both C# and PHP/MYSQL so that part is not a problem. Im just sort of new to client/server architecture in Unity.

Appreciate your input/insight guys.
Just wanted to get headed down the right path.

Seems sockets are not supported in Unity OS Basic. So I guess that rules that out.

Will using PHP/MySQL + WWW/WWWFOrm with JSON responses work well?
Also, Should I be constantly polling or load information once, then use internal timers on each object?

Bump…really no one? I just noticed this topic existed meanwhile just last night I posted this exact same question. Can someone PLEASE chime in

hi, have you found solution or answer? I have same question about how to make like clash of clans’s like building timer clock.

I think best answer is not use server when make buildings. Just use own phone’s local clock. Then only after finished building, send this info to server and store to serverside to block cheating.

Because checking time on being constructed building is not so important even if that user re-install game or migrate to another phone. Just let user know will lose progress.

What important is what buildings that user have.

Isn’t it?

My current project is similar to Clash of Clan, I am curious what is the method to achieve this.

If player change phone’s local clock then it will be a problem.

Not necessarily. You could update the server when a person clicks to start a building (with a timestamp), and the server will know that any completion notice before the amount of time required for that building is incorrect. If sockets aren’t available, simple GET requests should be just fine for this. You aren’t needing 20-30 updates a second, just every few seconds really.

You can use PHP.

Use POST, use PDO, and ensure you include a secure session id in the url for security.

You should have a “buildings” table which stores base build times of all buildings.
And a “builds” table which stores start times of all player build requests (you can remove rows that have finished building if you don’t want it logged forever).

#1: When a player requests to build something, send the start_time (unix timestamp) to the server and store it in “builds” along with the id of the building (and of course the player id).
#2: Time the build with a client-side timer (count down from build_time (in seconds) received by the server).
The build_time could depend on whether the player has some element that increases/decreases build time etc… calculate this server-side (you might want to store this in the “builds” table too so that you don’t have to recalculate it when doing the check in the next step). If it’s not dynamic like that, just send them the build_time of that specific build.
#3: When the build_time reaches 0, send a query to the server to determine whether it can be finished (compare the end_time with start_time + build_time (to unix)).
#4: If they’re not cheating, the server will tell them that the build is finished and remove the build from the “builds” table (unless you want to keep logs).
#5: If they are cheating, the server sends them the real current build_time and updates it to that.

I don’t see why you’d feel the need to constantly poll it unless your build times are in milliseconds.