Golang net.Dial() function examples
package net
Golang net.Dial() function usage examples
Example 1:
doc_socket, err := net.Dial("unix", "/var/run/docker.sock")
defer doc_socket.Close()
Example 2:
package main
import (
"fmt"
"net"
)
func main() {
hostName := "socketloop.com"
portNum := "80"
conn, err := net.Dial("tcp", hostName + ":" + portNum)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Connection established between %s and localhost.\n", hostName)
fmt.Printf("Remote Address : %s \n", conn.RemoteAddr().String())
fmt.Printf("Local Address : %s \n", conn.LocalAddr().String())
}
Sample output :
Connection established between socketloop.com and localhost.
Remote Address : 162.243.5.230:80
Local Address : 192.168.1.64:51810
References:
Advertisement
Something interesting
Tutorials
+7.1k Golang : Qt splash screen with delay example
+5.1k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+21.2k Golang : Read a file into an array or slice example
+18.3k Golang : How to Set or Add Header http.ResponseWriter?
+9k Golang : Convert octal value to string to deal with leading zero problem
+10.4k Golang : Generate DSA private, public key and PEM files example
+8.3k Golang : How to get ECDSA curve and parameters data?
+9.4k Golang : Meaning of omitempty in struct's field tag
+47k Golang : Upload file from web browser to server
+10.7k Golang : Calculations using complex numbers example
+5.1k Golang : Experimenting with the Rejang script