Example #1
0
func (ag *Agent) loops(user *User) {
	uniq := user.Session.ToUint()
	ag.maps[uniq] = user
	base.NOTICE("Join ", user.RemoteAddr())
	ag.loop(user)
	if ag.leavefunc != nil {
		ag.leavefunc(user)
	}
	ag.leave(uniq)
	base.NOTICE("Leave ", user.RemoteAddr())
	user.Close()
}
Example #2
0
func (se *Listener) Start() error {
	var err error
	base.NOTICE("Listen start from port", se.port)
	se.listener, err = net.Listen("tcp", fmt.Sprintf(":%d", se.port))
	if err != nil {
		base.ERR(err)
		return err
	}
	for {
		if conn, err := se.listener.Accept(); err == nil {
			go se.Listen(NewConnNet(conn))
		} else {
			base.ERR(err)
			return err
		}
	}
	base.NOTICE("Listen stop")
	return nil
}
Example #3
0
func (se *Server) Start() (err error) {
	base.NOTICE("Server start from port", se.port)
	se.listen, err = net.Listen("tcp", fmt.Sprintf(":%d", se.port))
	if err != nil {
		base.ERR(err)
		return
	}

	for {
		if conn, err := se.listen.Accept(); err == nil {
			go se.server.ServeConn(conn)
			//go h.Server.ServeCodec(jsonrpc.NewServerCodec(conn))
		} else {
			base.ERR(err)
			return err
		}
	}
	base.NOTICE("Server stop")
	return nil
}
Example #4
0
func tserver(t *testing.T) {
	ag := NewAgent(16, func(user *User, msg []byte) error {
		base.NOTICE(string(msg))
		user.WriteMsg(msg)
		user.Close()
		return nil
	}, nil)
	err := NewListener(7710, func(conn Conn) {
		ag.Join(conn)
	}).Start()
	checkError(err, t)
}
Example #5
0
func (se *ServerConfig) Start() {
	b := fmt.Sprintf("./%s", strings.ToLower(se.Type))
	args := []string{}
	if se.Bin != "" {
		b = fmt.Sprintf("./%s", se.Bin)
	}
	args = append(args, "-id", fmt.Sprintf("%d", se.Id))
	cmd := exec.Command(b, args...)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	base.NOTICE("Start", se.Id, se.Type, b)
	err := cmd.Start()
	if err != nil {
		base.ERR(err)
	}
}