42 lines
620 B
Go
42 lines
620 B
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"net"
|
|
"os"
|
|
|
|
"mcquay.me/robo"
|
|
)
|
|
|
|
const usage = "rsend <hostname>"
|
|
|
|
func main() {
|
|
if len(os.Args) != 2 {
|
|
fmt.Fprintf(os.Stderr, "%s\n", usage)
|
|
os.Exit(1)
|
|
}
|
|
|
|
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", os.Args[1], robo.Port))
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
s := bufio.NewScanner(os.Stdin)
|
|
for s.Scan() {
|
|
txt := s.Text()
|
|
fmt.Printf("sending: %s\n", txt)
|
|
_, err := conn.Write([]byte(txt + "\n"))
|
|
if err != nil {
|
|
break
|
|
}
|
|
}
|
|
|
|
if err := s.Err(); err != nil {
|
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|