robo/cmd/rrecv/main.go

44 lines
653 B
Go
Raw Normal View History

2015-02-04 21:08:44 -08:00
package main
import (
"bufio"
"fmt"
"net"
"os"
"mcquay.me/robo"
)
func main() {
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", robo.Port))
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
for {
conn, err := ln.Accept()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
s := bufio.NewScanner(conn)
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)
}
fmt.Printf("disconnect: %+v\n", conn)
}
}