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
+7.7k Golang : Generate human readable password
+11.1k Golang : Fix go.exe is not compatible with the version of Windows you're running
+11.6k Golang : Simple file scaning and remove virus example
+7.7k Golang : get the current working directory of a running program
+5k Golang : Constant and variable names in native language
+7.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+43.5k Golang : Get hardware information such as disk, memory and CPU usage
+6.9k Nginx : Password protect a directory/folder
+16.3k Golang : Loop each day of the current month example
+21.2k Golang : Clean up null characters from input data
+7.4k Golang : Scanf function weird error in Windows
+8.6k Golang : Convert(cast) []byte to io.Reader type