0

I'm trying to read data from some devices via telnet protocol and below is my simple code. I just want to print some meaningful results.

package main

import (
    "fmt"
    "github.com/reiver/go-telnet"

)

func main() {

    conn, _ := telnet.DialTo("10.253.102.41:23")
    fmt.Println(conn)
}

but this is what I got by this way: &{0xc000006028 0xc000004720 0xc000040640}

Morteza Hasanabadi
  • 212
  • 1
  • 2
  • 12
  • 2
    If you want to show data send by the server you should actually [read](https://godoc.org/github.com/reiver/go-telnet#Conn.Read) these. What you do here is just print the connection object. – Steffen Ullrich Aug 18 '19 at 07:01
  • 1
    of course, but it's not clear for me how to use it and also there isn't any example. – Morteza Hasanabadi Aug 19 '19 at 11:29

1 Answers1

0

It's obvious that it gets you &{0xc000006028 0xc000004720 0xc000040640} cause you are printing the connection object and it's the pointer address of that. If you want to print the data, you have to read it through connection using the Read method of the connection. Something like this:

b := make([]byte, 100)
n, err := conn.Read(b)
if err != nil {
    // handle error
}

fmt.Println(string(b))
meshkati
  • 1,720
  • 2
  • 16
  • 29
  • This is the revised code but still I can't print any data. `code conn, _ := telnet.DialTo("10.253.102.41:23") conn.Write([]byte("test")) conn.Write([]byte("\n")) b := make([]byte, 100) n, err := conn.Read(b) if err != nil { // handle error } fmt.Println(string(n)) }` – Morteza Hasanabadi Aug 19 '19 at 11:32