stephen mcquay
69d2c50dc5
if you read gob docs it states the following: " If a field has the zero value for its type, it is omitted from the transmission." That's powerful savings. I didn't know. Now it works as one would expect.
46 lines
660 B
Go
46 lines
660 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")
|
|
|
|
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 {
|
|
point := robo.Point{}
|
|
err = dec.Decode(&point)
|
|
if err != nil {
|
|
break
|
|
}
|
|
log.Printf("%+v", point)
|
|
}
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
|
}
|
|
|
|
log.Printf("disconnect: %+v\n", conn)
|
|
}
|
|
}
|