Golang net.IPConn.SetDeadline(), SetReadDeadline() and SetReadBuffer() functions example
package net
Golang net.IPConn.SetDeadline(), SetReadDeadline() and SetReadBuffer() functions usage example
package main
import (
"fmt"
"net"
"time"
)
func main() {
// replace x with your target IP address
raddr := &net.IPAddr{IP: net.IPv4(x, x, x, x).To4()}
laddr := &net.IPAddr{IP: net.IPv4(x, x, x, x)}
ipconn, err := net.DialIP("ip:tcp", laddr, raddr)
if err != nil {
fmt.Println("Error: ", err)
} else {
fmt.Println(ipconn)
}
defer ipconn.Close()
// the same can be applied to SetWriteDeadline() and SetWriteBuffer() functions as well
t := time.Now()
ipconn.SetDeadline(t.Add(100 * time.Millisecond))
ipconn.SetReadDeadline(t.Add(250 * time.Millisecond))
//buffer := make([]byte, 4096)
err := ipconn.SetReadBuffer(4096)
if err != nil {
fmt.Println("Error: ", err)
}
}
References :
http://golang.org/pkg/net/#IPConn.SetDeadline
Advertisement
Something interesting
Tutorials
+16k Golang : How to reverse elements order in map ?
+6.1k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+5.4k Unix/Linux/MacOSx : How to remove an environment variable ?
+5.4k Python : Delay with time.sleep() function example
+15.9k Golang : Get current time from the Internet time server(ntp) example
+18.6k Golang : Generate thumbnails from images
+26.9k Golang : Force your program to run with root permissions
+20.7k Golang : Saving private and public key to files
+15.4k Golang : Find location by IP address and display with Google Map
+7.3k Golang : How to iterate a slice without using for loop?
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error