Golang net.DialTimeout() function example
package net
Golang net.DialTimeout() function usage example
package main
import (
"fmt"
"net"
"time"
)
func main() {
hostName := "socketloop.com"
portNum := "80"
seconds := 5
timeOut := time.Duration(seconds) * time.Second
conn, err := net.DialTimeout("tcp", hostName+":"+portNum, timeOut)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Connection established between %s and localhost with time out of %d seconds.\n", hostName, int64(timeOut/(1000*time.Millisecond)))
fmt.Printf("Remote Address : %s \n", conn.RemoteAddr().String())
fmt.Printf("Local Address : %s \n", conn.LocalAddr().String())
}
Connection established between socketloop.com and localhost with time out of 5 seconds.
Remote Address : 162.243.5.230:80
Local Address : 192.168.1.64:52324
References :
Advertisement
Something interesting
Tutorials
+10.1k Golang : Edge detection with Sobel method
+18.6k Golang : Iterating Elements Over A List
+8.8k Golang : Get final balance from bit coin address example
+12.6k Golang : Exit, terminating or aborting a program
+21.8k Golang : Convert string slice to struct and access with reflect example
+7.9k Golang : Get today's weekday name and calculate target day distance example
+20.7k Golang : Read directory content with os.Open
+14k Golang : concatenate(combine) strings
+5.3k Golang : Get FX sentiment from website example
+10.5k Golang : Create matrix with Gonum Matrix package example
+4.7k Chrome : How to block socketloop.com links in Google SERP?
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example