Golang net.IPConn.Close(), Read() and ReadFrom() functions example
package net
Golang net.IPConn.Close(), Read() and ReadFrom() functions usage example.
func handleConnection(c net.Conn) {
log.Printf("Client(TLS) %v connected via secure channel.", c.RemoteAddr())
// stuff to do... like read data from client, process it, write back to client
// see what you can do with (c net.Conn) at
// http://golang.org/pkg/net/#Conn
buffer := make([]byte, 4096)
for {
n, err := c.Read(buffer)
if err != nil || n == 0 {
c.Close()
break
}
// n, addr, err := c.ReadFrom(buffer)
// fmt.Println(addr.String())
// if err != nil || n == 0 {
// c.Close()
// break
// }
n, err = c.Write(buffer[0:n])
if err != nil {
c.Close()
break
}
}
log.Printf("Connection from %v closed.", c.RemoteAddr())
}
See also : https://www.socketloop.com/tutorials/golang-secure-tls-connection-between-server-and-client
References :
https://www.socketloop.com/tutorials/golang-secure-tls-connection-between-server-and-client
http://golang.org/pkg/net/#IPConn.Read
Advertisement
Something interesting
Tutorials
+5.6k Golang : Detect words using using consecutive letters in a given string
+27.5k Golang : dial tcp: too many colons in address
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+8.2k Golang : HttpRouter multiplexer routing example
+27.2k Golang : Find files by name - cross platform example
+9.6k Golang : Quadratic example
+14.5k Golang : How to check if your program is running in a terminal
+19.3k Golang : Get RGBA values of each image pixel
+14.4k Golang : Parsing or breaking down URL
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+12.2k Golang : calculate elapsed run time