In Golang, i can close
a TCPListener
, however, i can not tell whether a TCPListener
is closed or not. This info could be used to do some other logic in program.
You could dial to the socket before using it:
_, err = net.Dial("tcp", "127.0.0.1:8021") //8021 is a closed socket
if err != nil {
panic("Error, socket not opened")
}
EDIT: Maybe this way is more clear:
isOpen := true
_, err = net.Dial("tcp", "127.0.0.1:8021") //8021 is a closed socket
if err != nil {
isOpen = false
}
if isOpen {
//Your logic here
}