Originally I thought that fmt.Fprintf
may be changing the request data on the way out, but this example seems to work OK.
However, I would still recommend using the lower-level Write/Read
instead of fmt.Fprintf/ioutil.ReadAll
:
req := []byte { 0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0xd5, 0xca }
n, err := conn.Write(req)
if err != nil {
fmt.Println("write error:", err)
return
}
fmt.Printf("wrote %d bytes for request: %#v", n, req)
rsp := make([]byte, 64)
n, err = conn.Read(rsp)
fmt.Printf("received %d bytes in response: %#v", n, rsp[:n])
if err != nil {
fmt.Println("read error:", err)
}