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
+8.6k Golang : Progress bar with ∎ character
+18.6k Golang : Find IP address from string
+15.8k Golang : How to login and logout with JWT example
+43.5k Golang : Get hardware information such as disk, memory and CPU usage
+9.5k Golang : Extract or copy items from map based on value
+7.7k Golang : Mapping Iban to Dunging alphabets
+11.6k Golang : Convert(cast) float to int
+15.4k Golang : Find location by IP address and display with Google Map
+20.2k Golang : Compare floating-point numbers
+8.8k Golang : Heap sort example
+8.3k Useful methods to access blocked websites
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name