Created
August 14, 2014 10:20
-
-
Save jasonberanek/badec0f4a1e4ee880b06 to your computer and use it in GitHub Desktop.
Go code used to investigate message across platforms for connecting to an address that is unavailable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"log" | |
"net" | |
"syscall" | |
"time" | |
) | |
func main() { | |
address := "127.0.0.1:5901" | |
log.Printf("Trying address: %s...", address) | |
l, err := net.DialTimeout("tcp", address, 2*time.Second) | |
if err == nil { | |
log.Printf("%s in use", address) | |
l.Close() | |
} else if e, ok := err.(*net.OpError); ok { | |
if e.Err == syscall.ECONNREFUSED { | |
// then port should be available for listening | |
log.Printf("ECONNREFUSED when connecting to: %s\n\t%v", address, e.Err) | |
} else if e.Timeout() { | |
log.Printf("Timeout connecting to: %s (check firewall rules)\n\t%v", address, e.Err) | |
} else { | |
log.Printf("Error when connecting to: %s\n\t%v", address, e.Err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment