Ejemplo n.º 1
0
//处理连接请求
func (this *server) handlerConnection(conn *net.TCPConn) {

	defer logger.CatchException()

	logger.Infof("New connection coming ... IP=%s ", conn.RemoteAddr())

	conn.SetNoDelay(true)                                        //无延迟
	conn.SetKeepAlive(true)                                      //保持激活
	conn.SetReadBuffer(64 * 1024)                                //设置读缓冲区大小
	conn.SetWriteBuffer(64 * 1024)                               //设置写缓冲区大小
	conn.SetReadDeadline(time.Now().Add(30000000 * time.Second)) //设置读超时

	session := network.NewSession(conn)
	defer session.Close()

	for {
		msg, err := session.RecvMSG()
		if err != nil {
			logger.Infof("RecvMsgs IP=%s err=%v", conn.RemoteAddr(), err.Error())
			return
		}

		ret := this.ProcessMessage(session, msg)
		if ret == false {
			return
		}
	}
}
Ejemplo n.º 2
0
func OnRun(cmd []string) {

	defer logger.CatchException()

	logger.Infof("OnRun")

	InitPacketHandler()

	//执行循环
	logger.Infof("ip = %v port = %v", config.SERVER_IP, config.SERVER_PORT)
	listen, err := net.ListenTCP("tcp", &net.TCPAddr{net.ParseIP(config.SERVER_IP), config.SERVER_PORT, ""})
	if err != nil {
		panic(err)
	}

	for {
		conn, e := listen.AcceptTCP()
		if e != nil {
			logger.Infof("[Main] => AcceptTCP failed! err=%v", e)
			continue
		}

		//协程处理
		go Server.handlerConnection(conn)
	}
}
Ejemplo n.º 3
0
func Run(index int) {
	defer logger.CatchException()

	logger.Errorf("index=%v", index)
	InitLog()
	InitConf(index)
	logger.Infof("server start...")

	InitZK()

	RunHttpServer()
}
Ejemplo n.º 4
0
func Run(index int) {
	defer logger.CatchException()

	logger.Errorf("index=%v", index)
	InitLog()
	InitConf(index)
	logger.Infof("server start...")

	InitZK()

	luascript.Init("LoginServer")

	HandlerPackageFunc()

	tcpaddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", config.SERVER_IP, config.SERVER_PORT))
	if err != nil {
		logger.Errorf("net.ResolveTCPAddr failed! err=%v", err)
		return
	}

	listener, err := net.ListenTCP("tcp4", tcpaddr)
	if err != nil {
		logger.Errorf("net.Listen failed! err=%v", err)
		return
	}

	for {
		conn, err := listener.AcceptTCP()
		logger.Infof("=>%v connecting...", conn.RemoteAddr().String())
		if err != nil {
			logger.Errorf("listener.Accept failed! err=%v", err)
			continue
		}

		go ProcessConnection(conn)
	}

}
Ejemplo n.º 5
0
func InitConf(index int) {
	config.LoadServerInfo(common.LOGIN_SERVER_TYPE, index)
	logger.Infof("[LoginServer] =>> ip=%v port=%v group=%v", config.SERVER_IP, config.SERVER_PORT, config.SERVER_GROUP)
}
Ejemplo n.º 6
0
func InitConf(index int) {
	config.LoadServerInfo(common.GATE_SERVER_TYPE, index)
	logger.Infof("ip=%v port=%v group=%v", config.SERVER_IP, config.SERVER_PORT, config.SERVER_GROUP)
}
Ejemplo n.º 7
0
func TestHandler(session *network.Session, message *network.Message) int {
	logger.Infof("TestHandler======================")
	session.SendMSG(message)

	return network.MESSAGE_DISCONNECT
}