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.6k PHP : Convert CSV to JSON with YQL example
+9.7k PHP : Get coordinates latitude/longitude from string
+7k Web : How to see your website from different countries?
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+6.3k Unix/Linux : Use netstat to find out IP addresses served by your website server
+8.6k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+13.7k Golang : Check if an integer is negative or positive
+10.7k Golang : Get currencies exchange rates example
+7.4k Golang : Individual and total number of words counter example
+11.3k Golang : How to flush a channel before the end of program?
+12.1k Golang : convert(cast) string to integer value
+14.1k Javascript : Prompt confirmation before exit