Golang net.ListenIP() function example
package net
Golang net.ListenIP() function usage example
package main
import (
"fmt"
"net"
"os"
)
func main() {
service := "127.0.0.1:8888"
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)
}
for {
// listen2Client function will listen forever until terminate
// up to you to define how listen2Client works...
listen2Client(IPconn)
}
}
Advertisement
Something interesting
Tutorials
+6.1k Golang : Get missing location after unmarshal binary and gob decode time.
+6.1k Golang : Dealing with backquote
+6.9k Golang : Calculate BMI and risk category
+18.6k Golang : Generate thumbnails from images
+23.5k Golang : Read a file into an array or slice example
+22.2k Golang : How to run Golang application such as web server in the background or as daemon?
+6.5k Golang : Convert an executable file into []byte example
+9.1k Golang : Simple histogram example
+7.6k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+6.1k Golang : Missing Subversion command
+8.8k Golang : Get final balance from bit coin address example
+16.1k Golang : How to check if input from os.Args is integer?