robo/cmd/rrecv/main.go

45 lines
624 B
Go

package main
import (
"encoding/gob"
"fmt"
"log"
"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)
}
point := robo.Point{}
for {
var err error
conn, err := ln.Accept()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
dec := gob.NewDecoder(conn)
for {
err = dec.Decode(&point)
if err != nil {
break
}
log.Printf("%+v", point)
}
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
fmt.Printf("disconnect: %+v\n", conn)
}
}