I have just started studying about IoT a few days ago, and now I'm trying to work with the wifi module ESP8266. I want to do something like this: I send a cmd from Android device to a server, which have some php code to handle my GET or POST data. Then, it will send some data, like json or something, to the ESP8266, and to a micro controller like AVR via UART to handle the changes. And sometime the MCU can send some data to server, and server will noti the android (a reverse process). I have understood how to send data from wifi module to an URL with Get and Post method (not fully, but maybe enough). I just dont understand how to send message from server to the module! Does the module need to send request to server and get the respone again and again in a loop?! I am a newbie so please give me a clear and answer! Thanks and sorry for bad English =)
In general servers do not push data to devices for several reasons. The most obvious reason is that the devices are behind routers which effectively hide them from the Internet.
Does the module need to send request to server and get the respone again and again in a loop?
Yes, that is the usual method. The device just needs regular Internet access and routers are usually configured to allow outbound HTTP traffic.
As this isn't an electrical design question it will probably be migrated to one of the other SE sites.
You could set up a MQTT broker (available both to the server and the ESP, so you would have figure out the networking and security).
The ESP would subscribe to a particular topic. On the server side you could use phpMQTT to connect to the broker and publish an event. The broker would then notify the ESP.