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
+5.2k Golang : Issue HTTP commands to server and port example
+19k Golang : Padding data for encryption and un-padding data for decryption
+6.9k Golang : Decode XML data from RSS feed
+20.9k Golang : Convert PNG transparent background image to JPG or JPEG image
+4.5k Java : Generate multiplication table example
+10.8k Android Studio : Checkbox for user to select options example
+6.4k PHP : Proper way to get UTF-8 character or string length
+21.1k Golang : Sort and reverse sort a slice of strings
+5.4k How to check with curl if my website or the asset is gzipped ?
+6.2k Linux/Unix : Commands that you need to be careful about
+5.2k Golang : Calculate half life decay example
+6.2k PHP : Get client IP address