示例#1
0
文件: conn.go 项目: Yuhang/xserver
func (h *connHandler) onSetPeerInfo(callback float64, r *amf0.Reader) error {
	const (
		keepAliveServer, keepAlivePeer = 1000 * 20, 1000 * 5
	)
	addrs := []*net.UDPAddr{}
	for r.Len() != 0 {
		if s, err := r.ReadString(); err != nil {
			return errors.New("conn.onSetPeerInfo.read address")
		} else if len(s) != 0 {
			if addr, err := net.ResolveUDPAddr("udp", s); err == nil {
				if ip4 := addr.IP.To4(); ip4 != nil {
					addr.IP = ip4
				}
				addrs = append(addrs, addr)
			} else {
				xlog.ErrLog.Printf("[session]: parse addr = %s, error = '%v', addr = [%s]\n", s, addr)
			}
		}
	}
	h.session.addrs = addrs
	if err := h.newKeepAliveResponse(keepAliveServer, keepAlivePeer); err != nil {
		return errors.New("conn.onSetPeerInfo.keep alive response")
	}
	return nil
}
示例#2
0
文件: message.go 项目: Yuhang/xserver
func handleAmfMessage(h messageHandler, r *amf0.Reader, withcallback bool) error {
	var err error
	name := ""
	if name, err = r.ReadString(); err != nil {
		return errors.New("message.amf.read name")
	}
	callback := float64(0)
	if withcallback {
		if callback, err = r.ReadNumber(); err != nil {
			return errors.New("message.amf.read callback")
		}
		if r.Len() != 0 && r.TestNull() {
			if err := r.ReadNull(); err != nil {
				return errors.New("message.amf.read null")
			}
		}
	}
	return h.OnAmfMessage(name, callback, r)
}