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) } }