I have a test program where I want to run multiple copies of the program from the command-line, and I need to know the first instance of the program to start. In Dart, I do the following which someone suggested to me :
RawServerSocket.bind("127.0.0.1", 8087)
If that fails, then I know that another program has "locked" the port. That solves the problem sufficiently well for me. The lock is released when the program terminates or when the socket is explicitly closed.
How can I achieve a similar result in Go?