46 lines
658 B
Go
46 lines
658 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)
|
|
}
|
|
|
|
log.Println("locked and loaded")
|
|
|
|
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)
|
|
}
|
|
}
|