With that in mind, the idea about your project is to create a server, which accepts connections from the port that your apps uses, and process the packets that receives from other devices. Then, depending on what is received, the ESP should write something through serial.
I would suggest you to use Arduino IDE with ESP8266 board, because it is so simple.
About the timeout, it is a requirement of the TCP protocol. When a client does not send packets in a very long time, the connection closes, because it's a way to proof that the client is still using the connection. A technique to avoid the timeout is to send an empty packet, so it shouldn't be a problem.
Summing up, the process could be:
- Connect to WiFi
Create the server in the correct port (accept function)
Receive the packets (callback functions) -> process the data and use the serial line to send information to the telescope.