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
+5.8k Javascript : How to replace HTML inside <div>?
+8.2k Golang : Qt splash screen with delay example
+11.9k Golang : Convert decimal number(integer) to IPv4 address
+18k Golang : Check if a directory exist or not
+6.4k Golang : Break string into a slice of characters example
+27.5k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+21.8k SSL : How to check if current certificate is sha1 or sha2
+6.1k Golang : Measure execution time for a function
+18.5k Golang : Aligning strings to right, left and center with fill example
+31.5k Golang : bufio.NewReader.ReadLine to read file line by line
+14.4k Golang : Find network of an IP address
+18.6k Golang : Get download file size