当前位置: 首页>>代码示例>>Golang>>正文


Golang Session.Send方法代码示例

本文整理汇总了Golang中github.com/idealeak/goserver/core/netlib.Session.Send方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Send方法的具体用法?Golang Session.Send怎么用?Golang Session.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/idealeak/goserver/core/netlib.Session的用法示例。


在下文中一共展示了Session.Send方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: OnRegiste

func (this *serviceMgr) OnRegiste(s *netlib.Session) {
	if this == nil || s == nil {
		return
	}

	if s.GetAttribute(SessionAttributeServiceFlag) == nil {
		return
	}
	attr := s.GetAttribute(SessionAttributeServerInfo)
	if attr != nil {
		if srvInfo, ok := attr.(*protocol.SSSrvRegiste); ok && srvInfo != nil {
			services := GetCareServicesBySession(srvInfo.GetType())
			for _, v1 := range services {
				if v2, has := this.servicesPool[v1]; has {
					for _, v3 := range v2 {
						func(si *protocol.ServiceInfo, sInfo *protocol.SSSrvRegiste) {
							pack := &protocol.SSServiceInfo{}
							proto.SetDefaults(pack)
							pack.Service = si
							logger.Trace("serviceMgr.OnRegiste Server Type=", sInfo.GetType(), " Id=", sInfo.GetId(), " Name=", sInfo.GetName(), " careful => Service=", si)
							s.Send(pack)
						}(v3, srvInfo)
					}
				}
			}
		}
	}
}
开发者ID:zwczou,项目名称:goserver,代码行数:28,代码来源:servicemgr.go

示例2: OnSessionOpened

func (sfl *SessionHandlerSrvRegiste) OnSessionOpened(s *netlib.Session) {
	registePacket := &protocol.SSSrvRegiste{
		Id:     proto.Int(netlib.Config.SrvInfo.Id),
		Type:   proto.Int(netlib.Config.SrvInfo.Type),
		AreaId: proto.Int(netlib.Config.SrvInfo.AreaID),
		Name:   proto.String(netlib.Config.SrvInfo.Name),
	}
	proto.SetDefaults(registePacket)
	s.Send(registePacket)
}
开发者ID:zwczou,项目名称:goserver,代码行数:10,代码来源:serversessionregiste.go

示例3: Process

func (this *SCPacketPongHandler) Process(session *netlib.Session, data interface{}) error {
	if pong, ok := data.(*protocol.SCPacketPong); ok {
		ping := &protocol.CSPacketPing{
			TimeStamb: proto.Int64(time.Now().Unix()),
			Message:   pong.GetMessage(),
		}
		proto.SetDefaults(ping)
		session.Send(ping)
	}
	return nil
}
开发者ID:zwczou,项目名称:goserver,代码行数:11,代码来源:scpacketponghandler.go

示例4: OnSessionOpened

func (af *AuthenticationFilter) OnSessionOpened(s *netlib.Session) bool {
	timestamp := time.Now().Unix()
	h := md5.New()
	sc := s.GetSessionConfig()
	h.Write([]byte(fmt.Sprintf("%v;%v", timestamp, sc.AuthKey)))
	authPack := &protocol.SSPacketAuth{
		Timestamp: proto.Int64(timestamp),
		AuthKey:   proto.String(hex.EncodeToString(h.Sum(nil))),
	}
	proto.SetDefaults(authPack)
	s.Send(authPack)
	return true
}
开发者ID:zwczou,项目名称:goserver,代码行数:13,代码来源:authentication.go

示例5: OnSessionOpened

func (sfcb *SessionHandlerClientBalance) OnSessionOpened(s *netlib.Session) {
	logger.Trace("SessionHandlerClientBalance.OnSessionOpened")
	services := srvlib.ServiceMgr.GetServices(srvlib.ClientServiceType)
	if services != nil {
		/*清理掉线的gate*/
		for k, _ := range sfcb.gates {
			if _, has := services[k]; !has {
				delete(sfcb.gates, k)
			}
		}
		/*补充新上线的gate*/
		for k, v := range services {
			if _, has := sfcb.gates[k]; !has {
				sfcb.gates[k] = &gateService{ServiceInfo: v, active: true}
			}
		}
	}

	/*查找最小负载的gate*/
	var mls *libproto.ServiceInfo
	var min = 100000
	for _, v := range sfcb.gates {
		if v.active && v.load < min {
			mls = v.ServiceInfo
		}
	}
	pack := &protocol.SCGateInfo{}
	if mls != nil {
		pack.SrvType = proto.Int32(mls.GetSrvType())
		pack.SrvId = proto.Int32(mls.GetSrvId())
		pack.AuthKey = proto.String(mls.GetAuthKey())
		pack.Ip = proto.String(mls.GetIp())
		pack.Port = proto.Int32(mls.GetPort())
	}
	proto.SetDefaults(pack)
	s.Send(pack)
	time.AfterFunc(time.Second*5, func() { s.Close() })
}
开发者ID:zwczou,项目名称:goserver,代码行数:38,代码来源:clientsessionhandler.go

示例6: ReportService

func (this *serviceMgr) ReportService(s *netlib.Session) {
	acceptors := netlib.GetAcceptors()
	cnt := len(acceptors)
	if cnt > 0 {
		pack := &protocol.SSServiceRegiste{
			Services: make([]*protocol.ServiceInfo, 0, cnt),
		}
		proto.SetDefaults(pack)
		for _, v := range acceptors {
			addr := v.Addr()
			if addr == nil {
				continue
			}
			network := addr.Network()
			s := addr.String()
			ipAndPort := strings.Split(s, ":")
			if len(ipAndPort) < 2 {
				continue
			}

			port, err := strconv.Atoi(ipAndPort[len(ipAndPort)-1])
			if err != nil {
				continue
			}

			sc := v.GetSessionConfig()
			si := &protocol.ServiceInfo{
				AreaId:          proto.Int32(int32(sc.AreaId)),
				SrvId:           proto.Int32(int32(sc.Id)),
				SrvType:         proto.Int32(int32(sc.Type)),
				SrvPID:          proto.Int32(int32(os.Getpid())),
				SrvName:         proto.String(sc.Name),
				NetworkType:     proto.String(network),
				Ip:              proto.String(sc.Ip),
				Port:            proto.Int32(int32(port)),
				WriteTimeOut:    proto.Int32(int32(sc.WriteTimeout / time.Second)),
				ReadTimeOut:     proto.Int32(int32(sc.ReadTimeout / time.Second)),
				IdleTimeOut:     proto.Int32(int32(sc.IdleTimeout / time.Second)),
				MaxDone:         proto.Int32(int32(sc.MaxDone)),
				MaxPend:         proto.Int32(int32(sc.MaxPend)),
				MaxPacket:       proto.Int32(int32(sc.MaxPacket)),
				RcvBuff:         proto.Int32(int32(sc.RcvBuff)),
				SndBuff:         proto.Int32(int32(sc.SndBuff)),
				SoLinger:        proto.Int32(int32(sc.SoLinger)),
				KeepAlive:       proto.Bool(sc.KeepAlive),
				NoDelay:         proto.Bool(sc.NoDelay),
				IsAutoReconn:    proto.Bool(sc.IsAutoReconn),
				IsInnerLink:     proto.Bool(sc.IsInnerLink),
				SupportFragment: proto.Bool(sc.SupportFragment),
				AllowMultiConn:  proto.Bool(sc.AllowMultiConn),
				AuthKey:         proto.String(sc.AuthKey),
				EncoderName:     proto.String(sc.EncoderName),
				DecoderName:     proto.String(sc.DecoderName),
				FilterChain:     sc.FilterChain,
				HandlerChain:    sc.HandlerChain,
				Protocol:        proto.String(sc.Protocol),
				Path:            proto.String(sc.Path),
			}
			pack.Services = append(pack.Services, si)
		}
		s.Send(pack)
	}
}
开发者ID:zwczou,项目名称:goserver,代码行数:63,代码来源:servicemgr.go

示例7: OnSessionIdle

func (kf *KeepAliveFilter) OnSessionIdle(s *netlib.Session) bool {
	p := &protocol.SSPacketKeepAlive{Flag: proto.Int32(0)}
	proto.SetDefaults(p)
	s.Send(p)
	return true
}
开发者ID:zwczou,项目名称:goserver,代码行数:6,代码来源:keepalive.go


注:本文中的github.com/idealeak/goserver/core/netlib.Session.Send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。