So here’s my problem. I need to launch a simple server program using RunTime
once it’s launched, the server program starts listening on port say 1234. and then my code will try to connect to the server program on port 1234. so here’s my code
Process p = Runtime.getRuntime().exec(server program);
//create a socket and trying to connect port 1234.
But the server program takes some time to be up and running. So what’s the best way to tell that the server is running and the port is listening so that I dont try to connect the server too early?
Thanks
You need to poll it. Add a loop that tries to connect to the server and sleeps before retries. (Don’t forget to limit the number of retries…)
You could also catch the server process’s output stream and look for some keyword in its output (à la “JBoss microcontainer started”), but that’s just… messy.