Golang net.IPConn type LocalAddr() and RemoteAddr() functions example
package net
Golang net.IPConn type functions usage example
NOTE : this example WILL NOT work in Golang's playground. You have to do it in your server
package main
import (
"fmt"
"net"
"os"
)
func main() {
service := "162.243.5.230" // change this
IPAddr, err := net.ResolveIPAddr("ip4", service)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
IPconn, err := net.ListenIP("ip:tcp", IPAddr)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Local address : ", IPconn.LocalAddr())
fmt.Println("Remote address : ", IPconn.RemoteAddr())
}
Sample output :
Local address : 162.243.5.230
Remote address :
<nil>
References :
Advertisement
Something interesting
Tutorials
+5k Google : Block or disable caching of your website content
+13.2k Golang : Convert(cast) int to int64
+20.2k Golang : Convert seconds to human readable time format example
+20k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+7.8k Swift : Convert (cast) String to Double
+21.5k Golang : How to read float value from standard input ?
+9.8k Golang : Qt get screen resolution and display on center example
+24.5k Golang : Time slice or date sort and reverse sort example
+5.4k Golang : What is StructTag and how to get StructTag's value?
+9.7k PHP : Get coordinates latitude/longitude from string
+13.8k Generate salted password with OpenSSL example
+37.5k Golang : Converting a negative number to positive number