Beispiel #1
0
func Logic(seq uint32, conn *net.UDPConn, req []byte, fromAddr *net.UDPAddr) {
	defer func() {
		if err := recover(); err != nil {
			fmt.Print(err)
		}
	}()

	var A, B uint32

	p := bytes.NewBuffer(req)
	binary.Read(p, binary.BigEndian, &A)
	binary.Read(p, binary.BigEndian, &B)

	var addIn AddIn

	addIn.A = A
	addIn.B = B

	addr, err := net.ResolveUDPAddr("udp", "127.0.0.1:3001")

	res, err := svrkit.RunRemote(seq, "Add", addr, &addIn, 1000)
	if err != nil {
		panic(fmt.Errorf("Add err: %v", err))
	}

	addOut := res.(*AddOut)

	svrkit.Infof("seq: %v a: %v b: %v sum: %v", seq, addIn.A, addIn.B, addOut.Sum)

	p = new(bytes.Buffer)
	binary.Write(p, binary.BigEndian, addOut.Sum)

	rsp := p.Bytes()

	_, err = conn.WriteToUDP(rsp, fromAddr)
	if err != nil {
		panic(err)
	}
}
Beispiel #2
0
func Logic(seq uint32, conn *net.UDPConn, req []byte, fromAddr *net.UDPAddr) {
	var a uint32
	var b uint32
	var sum uint32

	p := bytes.NewBuffer(req)
	binary.Read(p, binary.BigEndian, &seq)
	binary.Read(p, binary.BigEndian, &a)
	binary.Read(p, binary.BigEndian, &b)

	sum = a + b

	svrkit.Infof("seq: %v a: %v b: %v sum: %v", seq, a, b, sum)

	p = new(bytes.Buffer)
	binary.Write(p, binary.BigEndian, seq)
	binary.Write(p, binary.BigEndian, sum)

	_, err := conn.WriteToUDP(p.Bytes(), fromAddr)
	if err != nil {
		panic(err)
	}
}