From that error message, I suspect that you already have a running instance
of your program - as the message says, you are only allowed to listen
on a port once.
To avoid that, you could listen on port zero, which will choose an arbitrary
port (but then you'll need to print out the port number so that you can
know which port to use on the client).
By the way, your code is a little bit more complex than
it needs to be. Instead of this:
> service := ":5000"
> tcpAddr, err := net.ResolveTCPAddr("tcp", service)
> checkError(err)
> listener, err := net.ListenTCP("tcp", tcpAddr)
You could do:
service := ":5000"
listener, err := net.Listen("tcp", tcpAddr)
Similarly when dialing - there's no need to call ResolveTCPAddr
explicitly (and it's actually not as good if you do that,
because Dial will automatically use multiple IP addresses
if it needs to, but if you use ResolveTCPAddr, it can only use one).
Hope this helps,
rog.