I'm writing a system where two programs will asynchronously communicate over a TCP socket. The client is written in golang, but the server might vary. I'm currently writing one in C#.
During development, I used
conn, err := net.Dial("tcp", net.JoinHostPort("127.0.0.1", strconv.Itoa(d.port)))
for the client, and on the server I did:
this.listener = new TcpListener(IPAddress.Parse("127.0.0.1"), port);
However, for production, I suspect that might not work in all cases. For example, the user might use IPv6. I also tried localhost
on the server, but on Windows that doesn't seem to be the same as 127.0.0.1
by default (it has to be enabled, which is not an option).
Is there a more fool-proof way of running a local TCP server, that should work in all cases?