Then the Arduino sketch: http://pastebin.com/vfQu9Mr8
And finally the python server: http://pastebin.com/hjwNndRL
As you can see the Arduino sketch connects to the computer using port 49000 (the test server is SocketTest). Then it sends the hello world! string indefinitely until the sketch receives the reboot command, in which case the sketch connects to the computer using port 50000 in data mode. After that, the sketch sends the hello string and waits for a welcome string sended by the Python server. The next step is to send the .hex file that is wanted to be "served" and wait an ok from Python server. When it is received the last step is to reboot Arduino... How is it done?, well, when Arduino reboots, every pin is configured as INPUT, so you can connect pin 12 and reset pin directly, when you want to reset Arduino you have to configure pin 12 as OUTPUT and set it to LOW to perfom a reset like you press the reset button.
hosting imagenes
The Python server is waiting a 0 byte (the one that Arduino sends when enter in bootloader) to begin the stk500 protocol (You can find a good explanation about the protocol in Arduino here: http://baldwisdom.com/bootloading/ The official document is here: http://www.atmel.com/Images/doc2525.pdf ). If everything is success the Arduino board will have the required hex file programmed into its FLASH memory. The python server closes the TCP connection for two reasons:
1-To force ESP8266 to leave data mode (You can exit sending +++ as I posted in other thread, but if the connection is closed then it leaves data mode too)
2-To listen to other sketches querying other .hex files.
Finally in the video you can watch how the Arduino connects again to the server with port 49000 and send hello world! as is programmed in the sketch.
Oh, I forgot to say the ESP8266 firmware version is 00180902. I had troubles with previous versions.