示例#1
0
func (this *STree) SendHeartBeat() {
	for {
		packet := structure.Packet{}
		packet.Number = define.HEART_BEAT
		packet.Uuid = define.P_UID
		packet.DataLen = 12
		packet.Data = make([]byte, packet.DataLen)

		this.SelfInfo.Lock.RLock()
		userNumber := this.SelfInfo.UserNumber
		maxConn := this.SelfInfo.MaxConnNumber
		currConn := this.SelfInfo.CurrentConnNumber
		this.SelfInfo.Lock.RUnlock()

		binary.BigEndian.PutUint32(packet.Data[0:4], uint32(userNumber))
		binary.BigEndian.PutUint32(packet.Data[4:8], uint32(maxConn))
		binary.BigEndian.PutUint32(packet.Data[8:12], uint32(currConn))
		GetParentHandler().SendToParent(&packet)
		time.Sleep(time.Duration(this.Seconds * 1000 * 1000 * 1000))
	}
}
示例#2
0
func (this *ClientHandler) sendAllocReq(conn *net.Conn) (*structure.Packet, error) {
	buf := make([]byte, 19)
	_, err := (*conn).Read(buf)
	if err != nil {
		err = errors.New("component: sendAllocReq() failed, can not read a log in message from conn")
		fmt.Println(err.Error())
		(*conn).Close()
		return nil, err
	}
	req := structure.Packet{}
	err = req.Decode(buf)
	if err != nil {
		err = errors.New("component: sendAllReq() failed, can not get message from received buf")
		fmt.Println(err.Error())
		(*conn).Close()
		return nil, err
	}
	req.Number = define.ALLOC_SERVER
	req.DataLen = 0
	req.Data = nil
	GetDaughterHandler().PushToDaughter(&req)
	return &req, nil
}