Connecting the agent to the master
is a robust way to connect. Many users around the world use that method to connect agents to masters, including Windows masters, Linux masters, and other platforms.
If the agent is being disconnected after some time, there may be something on the agent computer which kills the client process that runs on the agent (for example, some program that won't allow Java programs to run for an extended period). If the agent process dies or is killed on the agent computer, the agent will be disconnected. If you're running the agent process from the command line, then you may find hints to the cause of the command line failure in the command prompt window that launched the agent. If you're running the agent process by clicking the "Launch" button to launch the agent from the browser, you may want to try running the agent from the command line instead, just in case some diagnostic messages might help you.
There may be something in the networking definition between the master and the agents which is causing the agent process to die. Usually, when the network connection is interrupted between a master and agent launched to connect to the master. This seems less likely to be the problem, since you mentioned that the when running as a restart, the service restarted frequently.