Beispiel #1
0
//---------------------------------------------
//          server
//---------------------------------------------
func server() {
	engine := msgE.NewEngine("interServer")
	engine.RegisterMsg(111, RecvMsg)
	//设置自定义权限验证
	engine.SetAuth(new(CustomAuth))
	engine.Listen("127.0.0.1", 9090)
	time.Sleep(time.Second * 10)
}
//---------------------------------------------
//          server
//---------------------------------------------
func server() {
	engine := msgE.NewEngine("interServer")
	engine.RegisterMsg(111, RecvMsg)
	//添加一个拦截器
	engine.AddInterceptor(new(MyInterceptor))
	engine.Listen("127.0.0.1", 9090)
	time.Sleep(time.Second * 10)
}
//---------------------------------------------
//          server
//---------------------------------------------
func server() {
	engine := msgE.NewEngine("interServer")
	engine.RegisterMsg(111, RecvMsg)

	//设置回调函数
	engine.SetCloseCallback(CloseConnCall)
	engine.Listen("127.0.0.1", 9090)
	time.Sleep(time.Second * 1000)
	// session, _ := engine.GetController().GetSession("1")
	// session.Close()
}
Beispiel #4
0
//---------------------------------------------
//          client
//---------------------------------------------
func client() {
	engine := msgE.NewEngine("interClient")
	engine.RegisterMsg(111, ClientRecvMsg)
	engine.AddClientConn("test", "127.0.0.1", 9090, false)

	//给服务器发送消息
	session, _ := engine.GetController().GetSession("test")
	hello := []byte("hello, I'm client")
	session.Send(111, &hello)
	time.Sleep(time.Second * 10)

}
Beispiel #5
0
//启动消息服务器
func (this *Manager) initMsgEngine(name string) {
	this.hostIp = GetLocalIntenetIp()
	l, err := net.ListenPacket("udp", this.hostIp+":")
	if err != nil {
		fmt.Println("获取端口失败")
		return
	}
	hostPort, _ := strconv.Atoi(strings.Split(l.LocalAddr().String(), ":")[1])
	this.HostPort = int32(hostPort)

	fmt.Println("本机服务地址:", this.hostIp, ":", this.HostPort)
	this.serverManager = msgE.NewEngine(name)
	this.serverManager.SetAuth(new(Auth))
	this.serverManager.Listen(this.hostIp, this.HostPort)

}
Beispiel #6
0
//---------------------------------------------
//          server
//---------------------------------------------
func server() {
	engine := msgE.NewEngine("interServer")
	engine.RegisterMsg(111, RecvMsg)
	engine.Listen("127.0.0.1", 9090)
	time.Sleep(time.Second * 10)
}