September 2017
Intermediate to advanced
466 pages
9h 33m
English
The name of the Unix socket client program is socketClient.go and will be presented in four parts.
The first part of the utility contains the expected preamble:
package main import ( "fmt" "io" "log" "net" "os" "time" )
There is nothing special here, just the required Go packages. The second portion contains the definition of a Go function:
func readSocket(r io.Reader) {
buf := make([]byte, 1024)
for {
n, err := r.Read(buf[:])
if err != nil {
fmt.Println(err)
return
}
fmt.Println("-> ", string(buf[0:n]))
}
}
The readSocket() function reads the data from a socket file using Read(). Note that, although socketClient.go just reads from the socket file, the socket is bisectional, which means that you can also write to it. ...
Read now
Unlock full access