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
+87.7k Golang : How to convert character to ASCII and back
+7.7k Golang : Command line ticker to show work in progress
+21.6k Golang : GORM create record or insert new record into database example
+13k Golang : Calculate elapsed years or months since a date
+8k Golang : Sort words with first uppercase letter
+8.6k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+11.1k Golang : Fix go.exe is not compatible with the version of Windows you're running
+32.1k Golang : Validate email address with regular expression
+22.9k Golang : Gorilla mux routing example
+5.2k PHP : See installed compiled-in-modules
+16.6k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file