[go-nuts] Re: Network error handle

2016-12-11 Thread Stannis Kozlov
Thanks, folks! It's clear now: func sock() { conn, err := net.Dial("tcp", "192.168.0.1:80") if err != nil { fmt.Printf("\nDial has an error for you: %v\n", err) return } fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n") status, err := bufio.NewReader(conn).ReadString('\n') fmt.Printf

[go-nuts] Re: Network error handle

2016-12-11 Thread Dave Cheney
Your printf does not include a newline character, so the panic message is from your usage of conn in the line fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n") Because an error occured during the dail, you cannot use or assume conn has any sensible value. On Sunday, 11 December 2016 21:43:02 UTC+11,

[go-nuts] Re: Network error handle

2016-12-11 Thread Stannis Kozlov
I've modified the function accordingly: func sock() { conn, err := net.Dial("tcp", "192.168.0.1:9991") if err != nil { fmt.Printf("\nDial has an error for you %v", err) } fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n") status, err := bufio.NewReader(conn).ReadString('\n') fmt.Printf("

[go-nuts] Re: Network error handle

2016-12-10 Thread Lee McLoughlin
On a Dial error conn will be nil. Remove the call to conn.Close() On Saturday, 10 December 2016 23:28:36 UTC, Stannis Kozlov wrote: > > I'm trying to write simple port scanner and using "net" to check port > availability: > func sock() { > conn, err := net.Dial("tcp", "192.168.0.1:9991") > if

[go-nuts] Re: Network error handle

2016-12-10 Thread yannick . haessler
conn is probably nil if there is an error. Call Close only if there is no error. conn, err := net.Dial(...) if err != nil { // handle error } defer conn.Close() Am Sonntag, 11. Dezember 2016 00:28:36 UTC+1 schrieb Stannis Kozlov: > > I'm trying to write simple port scanner and using "net" to