You could start with:
socat tcp-l:8080,fork,reuseaddr \
SYSTEM:'nc -z 127.0.0.1 22 >/dev/null && exec nc 127.0.0.1 22 || echo Failed'"Fail!"'
So, Instead of tcp:127.0.0.1:12345 you spawn a shell_fragment/script, that more-or-less:
Check, if 127.0.0.1 12345 responds
if yes, connect there and pass over the fds (exec)
if no, echo "Service@12345 is down"
Optional: don't exit, but enter a while loop
Try reaching port 12345, then connect eventually
For the Optional part, just replace 'echo "Fail!" from above with
{ echo "SomeMsg; MoreCommands; }
I can help, if you need help adapting this, just update your Q with info where you got stuck