This is a creation in Article, where the information may have evolved or changed.
Package NetTools//main//import ("FMT" "Net" "StrConv" "Strings" "Time") func Smain () {lis, err: = Net. Listen ("TCP", ": 1789") if err! = Nil {fmt. PRINTLN (Err)}defer lis. Close () for {con, _: = Lis. Accept () go handler (Con)}}func handler (Con net. Conn) {defer con. Close () Buf: = Make ([]byte,] n, _: = Con. Read (BUF) fmt. Println (String (buf[:n])) con. Write (BUF) con. Write (BUF)}//func main () {//buf, err: = Telnet ([]string{"W_hello World", "r_50", "r_30"}, "127.0.0.1:1789")//fmt. PRINTLN (Err)//fmt. Println (String (buf))//}func portisopen (IP string, timeout int) bool {con, err: = Net. Dialtimeout ("tcp", IP, time. Duration (timeout)) If err! = Nil {return False}con. Close () return true}func Telnet (action []string, IP string, timeout int) (buf []byte, err error) {con, err: = Net. Dialtimeout ("tcp", IP, time. Duration (timeout) *time. Second) If err! = nil {Return}defer con. Close () con. Setreaddeadline (time. Now (). ADD (time. Second * 5)) for _, V: = Range Action {l: = strings. Splitn (V, "_", 2) If Len (L) < 2 {Return}switch l[0] {case "R": var n intn, err = StrConv. Atoi (l[1]) if err! = Nil {return}p: = make ([]byte, N) n, err = con. Read (P) if err! = Nil {return}buf = append (buf, p[:n] ...) Fmt. PRINTLN (BUF) Case "W": _, Err = con. Write ([]byte (L[1]))}}return}