robo/cmd/rserver/main.go

46 lines
658 B
Go
Raw Normal View History

2015-02-04 21:08:44 -08:00
package main
import (
2015-02-04 21:24:45 -08:00
"encoding/gob"
2015-02-04 21:08:44 -08:00
"fmt"
2015-02-04 21:24:45 -08:00
"log"
2015-02-04 21:08:44 -08:00
"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)
}
2015-02-04 21:35:25 -08:00
log.Println("locked and loaded")
2015-02-04 21:24:45 -08:00
point := robo.Point{}
2015-02-04 21:08:44 -08:00
for {
2015-02-04 21:24:45 -08:00
var err error
2015-02-04 21:08:44 -08:00
conn, err := ln.Accept()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
2015-02-04 21:24:45 -08:00
dec := gob.NewDecoder(conn)
for {
err = dec.Decode(&point)
2015-02-04 21:08:44 -08:00
if err != nil {
break
}
2015-02-04 21:24:45 -08:00
log.Printf("%+v", point)
2015-02-04 21:08:44 -08:00
}
2015-02-04 21:24:45 -08:00
if err != nil {
2015-02-04 21:08:44 -08:00
fmt.Fprintf(os.Stderr, "%v\n", err)
}
fmt.Printf("disconnect: %+v\n", conn)
}
}