示例#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))
	}
}