robo/cmd/rsend/main.go

42 lines
620 B
Go
Raw Normal View History

2015-02-04 21:08:44 -08:00
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)
}
}