コード例 #1
0
func main() {

	buff := make([]byte, 128)
	conn, err := net.Dial("tcp", "192.168.0.9:8001")
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	defer conn.Close()
	p := &rocproto.Packet{}
	for i := 0; i < 5; i++ {
		r, err := conn.Read(buff)
		if err != nil {
			fmt.Println(err.Error())
			return
		}
		err = proto.Unmarshal(buff[:r], p)
		if err != nil {
			fmt.Println(err.Error())
			return
		}

		fmt.Printf("Gps Coordinates : %+v\n", p.Coord)
	}

}
コード例 #2
0
func TestLinker_SendRemote(t *testing.T) {

	client := roc_test.ClientWs{}
	go client.Start(connParamDefault.rIp)
	defer client.Stop()
	<-time.After(time.Millisecond * 200)

	p := goPack.Prepare(1, rocproto.Packet_COMMAND, rocproto.Packet_CONTROL_SERVER, rocproto.Packet_VIDEO_CLIENT)
	err := l.send(p)
	if err != nil {
		t.Error(err)
	}
	select {
	case <-time.After(time.Millisecond * 5):
		t.Error("Time out > 5ms")
	default:
		b := client.Rcv()
		p2 := rocproto.Packet{}
		err := proto.Unmarshal(b, &p2)
		if err != nil {
			t.Error(err)
		}
		if *p != p2 {
			t.Error("Message different from original")
		}
	}
}
コード例 #3
0
func main() {

	u := url.URL{Scheme: "ws", Host: "192.168.0.9:8001", Path: "/controls"}
	log.Printf("connecting to %s\n", u.String())

	c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
	if err != nil {
		log.Fatal("dial:", err)
	}
	defer c.Close()

	c.WriteMessage(int(message.MessageBinary), []byte("test"))
	for {
		_, b, err := c.ReadMessage()
		if err != nil {
			fmt.Println(err)
			continue
		}
		p := rocproto.Packet{}
		err = proto.Unmarshal(b, &p)
		if err != nil {
			fmt.Println(err)
			continue
		}
		fmt.Printf("%+v\n", p)
	}
}
コード例 #4
0
func checkBuffer(r int, buff []byte, m *rocproto.Packet) (err error) {

	if r > -1 {
		err = proto.Unmarshal(buff[0:r], m)
	} else {
		err = proto.Unmarshal(buff[0:], m)
	}
	if err != nil {
		err = errors.New(fmt.Sprintln("Cannot Unmarshall packet : ", err.Error(),
			"\nlength ==> ", r, "\nbuffer ==> ", buff[0:]))
		log.Println(err.Error())
		return err
	}
	if m.Magic != Magic {
		log.Println("Wrong message format")
		return errors.New("Wrong message packet")
	}
	return nil
}