How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need.

I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes.

I'm using Cygwin bash on Windows 10.

My compileDeployStartWebServer.sh compiles the java code and starts the web server on port 8080.

Presently, the "StartBrowser.sh" sleeps for 40 seconds and launches a browser like Chrome or Firefox while the "compileDeployStartWebServer.sh" downloads any dependencies using maven or gradle, compiles the code and starts the web server. This takes a while!

So my plan was to enhance the java startup code in the web site to write "starting" to a UDP socket on port 7777. Alternatively, the java startup code could spawn a new child thread to write "starting" to a TCP socket so it the web site startup code won't block on the TCP socket in case I decide to run without the "StartBrowser.sh" script.

So is there a way to enhance the "StartBrowser.sh" to block on the TCP (or UDP) socket instead of sleeping? I could write some more java code, I suppose.

What would you recommend? UDP? TCP? What could I use to block the "StartBrowser.sh" (besides more custom java code) while the other script is busy downloading dependencies, compiling, deploying and starting the web server? flock?, exec? netcat? socat? something else?

Perhaps I should be using mutexes or semaphores instead? I don't think java has good support for these features, however.

Thanks
Siegfried

I must be missing something. It seems like you are making a very simple problem very complicated.

If you want to build and start a web server and, after the web server starts, start a browser; why not do the build and browser launch in a single script with three steps:

  1. build web server
  2. start web server
  3. start browser

Why do you need two separate scripts that have to do a lot of extra work to coordinate actions in the second script just because there is a second script?

Don:
Starting the build and starting the web server is done with a single maven command and the script is terminated with a kill or windows taskkill command. So you cannot have that script start a browser after the web server starts.
For classroom demonstrations, it is nice to have a single key stroke to run the demo.

Actually, I think I found the answer to my question:

Inserting

socat -u tcp-l:7777 system:

before launching the browser seems to work with my toy java TCP client.

Thanks
Siegfried

OK, but even so: how abou creating a script like this:

#! /bin/sh

if single-maven-command ; then
     start-browser-script.sh
else
   echo "Something went wrong executing maven..."
   exit 1
fi
exit 0