Avatar
2
hovanvydut Beginner
hovanvydut Beginner
Cách mà ezyfox quản lý các bean
Dạ em chào anh, em có pull source code ezyfox server và chạy thử example hello word của anh.<p> Em có đọc qua source code nhưng vẫn chưa hiểu hết, và có một số thắc mắc, có gì nhờ anh giúp đỡ ạ: </p> <p> Em thấy trong source example của anh có ví dụ sau: </p> <div class="markdown-block position-relative overflow-auto source-java"> <pre> <span class="pl-s">@Setter</span> <span class="pl-s">@EzyPrototype</span> <span class="pl-s">@EzyObjectBinding</span>(write = false) <span class="pl-s">@EzyRequestListener</span>(GREET) <span class="pl-k">public</span> <span class="pl-k">class</span> GreetRequestHandler <span class="pl-k">extends</span> ClientRequestHandler <span class="pl-k">implements</span> EzyDataBinding { private String who; <span class="pl-s">@EzyAutoBind</span> private Greeting greeting; <span class="pl-s">@Override</span> <span class="pl-k">protected</span> <span class="pl-k">void</span> execute() throws EzyBadRequestException { responseFactory.newObjectResponse() .command(GREET) .param(<span class="pl-s">"message"</span>, greeting.greet(who)) .session(session) .execute(); } } </pre> </div>Và trước kia em thắc mắc làm sao để biết command nào để biết listen handler tương ứng. Sau khi đọc thì em thấy anh quản lý các lớp này bằng cách đưa nó vào một cái <code class="markdown-inline">singletonSet</code> ở <code class="markdown-inline">EzySimpleFactoryClass</code>. Và lúc có request gửi lên anh dựa vào command id để lấy listener tương ứng. Tuy nhiên em "KHÔNG THẤY" đoạn anh khởi tạo và add các listener này vào <code class="markdown-inline">singletonSet</code> ở <code class="markdown-inline">EzySimpleFactoryClass</code>. Em chỉ thấy đoạn get này ở <code class="markdown-inline">EzyUserRequestSingletonController</code>:<div class="markdown-block position-relative overflow-auto source-java"> <pre> private Map&lt;String, EzyUserRequestHandlerProxy&gt; extractRequestHandlersFromListener() { List&lt;Object&gt; clientRequestHandlers = getClientRequestHandlers(); Map&lt;String, EzyUserRequestHandlerProxy&gt; handlers = <span class="pl-k">new</span> HashMap&lt;&gt;(); <span class="pl-k">for</span> (Object handler : clientRequestHandlers) { Class&lt;?&gt; handleType = handler.getClass(); EzyRequestListener annotation = handleType.getAnnotation(EzyRequestListener.class); String command = EzyRequestListenerAnnotations.getCommand(annotation); handlers.put(command, <span class="pl-k">new</span> EzyUserRequestHandlerProxy((EzyUserRequestHandler) handler)); logger.debug("add command {} and request handler {}", command, handler); } <span class="pl-k">return</span> handlers; } private List&lt;Object&gt; getClientRequestHandlers() { <span class="pl-k">return</span> singletonFactory.getSingletons(EzyRequestListener.class); } </pre> </div>và <code class="markdown-inline">getSingletons</code> ở EzySimpleSingletonFactory là anh duyệt qua <code class="markdown-inline">singletonSet</code> để tìm instance có chưa annotation <code class="markdown-inline">EzyRequestListener</code><div class="markdown-block position-relative overflow-auto source-java"> <pre> <span class="pl-k">public</span> List getSingletons(Class... annotationClasses) { <span class="pl-k">return</span> this.getSingletons((o) -&gt; { Class[] var2 = annotationClasses; <span class="pl-k">int</span> var3 = annotationClasses.length; <span class="pl-k">for</span>(int var4 = 0; var4 &lt; var3; ++var4) { Class annotationClass = var2[var4]; <span class="pl-k">if</span> (o.getClass().isAnnotationPresent(annotationClass)) { <span class="pl-k">return</span> true; } } <span class="pl-k">return</span> false; }); } <span class="pl-k">public</span> List getSingletons(Predicate filter) { List list = <span class="pl-k">new</span> ArrayList(); Iterator var3 = this.singletonSet.iterator(); <span class="pl-k">while</span>(var3.hasNext()) { Object object = var3.next(); <span class="pl-k">if</span> (filter.test(object)) { list.add(object); } } <span class="pl-k">return</span> list; } </pre> </div>
Answer
Avatar
1
MisYuy Beginner
MisYuy Beginner
Động bộ di chuyển Players MMO
Phương pháp có thể đảm bảo các yếu tố: <ul> <li>Lag thấp.</li> <li>Chống hack or cheat.</li></ul> <p> Em có tìm hiểu và thấy 2 phương pháp chính là: </p> <ul> <li>Client gửi trực tiếp vị trí hiện tại liên tục: Đơn giản nhất nhưng có vẻ hiệu năng không cao.</li> <li>Client gửi input và server tính toán gửi lại vị trí cho các players.</li></ul> <p> Em muốn hỏi là ngoài ra còn cách nào tốt hơn không, nếu không thì trong hai cách này thì cái nào tối ưu hơn vậy ạ. </p> <p> Em cám ơn! </p>
Answer
Avatar
0
tvd12 Enlightened
tvd12 Enlightened
[EzyFox Server] EzySimpleSessionManagementSetting, stress test
E xin lỗi vì phiền anh giờ này. A có thể trả lời khi rảnh ạ. Tại em chỉ muốn hiểu thêm về cấu trúc của Ezyfox. <ol start="1"> <li>Điểm khác biệt của EzySimpleSessionManagementSetting và EzySessionManagementSettingBuilder là gì ạ? Mình nên xài cái nào cho phần EzySimpleSetting?</li> <li>Việc stress test bắt buộc phải trong điều kiện mạng ổn định và băng thông phải mạnh à anh? Kiểu em về nhà test ở mạng nhà trọ thì nó run ngáo luôn reconnection udp r tcp socket ạ.</li></ol>
Answer
Avatar
1
Nguyễn Minh Thuận Beginner
Stress test Login Server in Ezyfox
Xin chào mọi người, em hiện tại đang gặp một số vấn đề về stress test login của Ezyfox. Em có một số câu hỏi như sau: <ol start="1"> <li>Khi mà em run stress test TCP login thì Server có thể nhận và phản hồi hơn 20k request. Nhưng khi em run UDP thì chỉ đạt ngưỡng tầm hơn 4k request thì bị nghẽn server (CPU đạt tới 100% do không remove User, ở Stress Test UDP thì bị lost Ping và try connected liên tục). Ở hình dưới, em thử chạy 6000 request UDP trong vòng 300s, nhưng số liệu request thực thì chỉ có 4641 và respone về login chỉ có 3820. Em có thể giải quyết vấn đề test UDP login như thế nào ạ?</li> <li>Cả TCP và UDP đều gặp vấn đề remove User rất chậm nếu User tự động ngắt kết nối số lượng lớn (Tắt stress test hoặc run xong stress test). Bên em thì không có luồng code socket về Remove User. Anh có thể hướng dẫn hoặc gửi tài liệu cho em đọc để fix vấn đề này được không ạ?</li> </ol> <p> Em cám ơn mọi người đã đọc </p> <img src="/api/v1/media/16a23a1e3ed481a9fa633789889abc48ca100289fae21e9b84cb3848f3452db6.png" alt="363805065_1013847862944408_8675372891581784208_n.png">
Answer
Avatar
0
tvd12 Enlightened
tvd12 Enlightened
Hỏi thêm về response từ ezyfox server về client
Anh ơi, em muốn hỏi thêm về response từ Server về client. Phía dưới là đoạn main trong TCPSocket của em, em mong muốn là nó chỉ login 1 lần và trả về kết quả chỉ 1 lần thôi. Hiện tại em đang bị nó trả về liên tục nên không thể biết được là số response / user là bao nhiêu và cũng như là số request / giây, số response / giây, số response / số request. <div class="markdown-block position-relative overflow-auto source-java"> <pre> <span class="pl-k">public</span> <span class="pl-k">static</span> <span class="pl-k">void</span> main(String[] args) { DefaultClientConfig clientConfig = <span class="pl-k">new</span> DefaultClientConfig(); SocketClientSetup setup = <span class="pl-k">new</span> SocketClientSetup(<span class="pl-s">"tcp-socket"</span>); EzyClients clients = EzyClients.getInstance(); EzyEventLoopGroup eventLoopGroup = <span class="pl-k">new</span> EzyEventLoopGroup(1); EventLoopGroup nettyEventLoopGroup = <span class="pl-k">new</span> EzyNettyEventLoopGroup(1); LocalDateTime Starttime = java.time.LocalDateTime.now(); LocalDateTime Endtime = null; <span class="pl-k">long</span> differentInSeconds = 0; <span class="pl-k">new</span> Thread(() -&gt; { <span class="pl-k">int</span> clientCount = 10; <span class="pl-k">for</span> (int i = 0; i &lt; clientCount; i++) { EzyTcpClient client = <span class="pl-k">new</span> EzyTcpClient( clientConfig.get(i), eventLoopGroup, nettyEventLoopGroup ); <span class="pl-k">try</span> { Thread.sleep(25); } <span class="pl-k">catch</span> (Exception e) { e.printStackTrace(); } setup.setup(client, false); clients.addClient(client); client.connect(<span class="pl-s">"127.0.0.1"</span>, 3005); } }) .start(); Endtime = java.time.LocalDateTime.now(); differentInSeconds = Duration.between(Starttime, Endtime).getSeconds(); System.out.println(<span class="pl-s">"===================StartTime=================="</span>); System.out.println(Starttime); System.out.println(<span class="pl-s">"===================EndTime=================="</span>); System.out.println(Endtime); System.out.println(<span class="pl-s">"===================Duration=================="</span>); System.out.println(differentInSeconds); EzyMainEventsLoop mainEventsLoop = <span class="pl-k">new</span> EzyMainEventsLoop(); mainEventsLoop.start(1); } </pre> </div>
Answer
Avatar
0
tvd12 Enlightened
tvd12 Enlightened
Hỏi về stress test cho ezyfox server
Anh ơi, em xin phép được hỏi một số câu. <ol start="1"> <li>Việc kết nối stress test có thể chạy ở 1 máy khác mà k nhất thiết server phải chạy không anh?</li> <li>Như hình 1 thì muốn chạy stress test phần login mình sẽ cho 5 máy khác chạy phần này đúng không anh? <a href="https://github.com/tvd12/ezyfox-server-example/tree/master/message-stresstest" target="_blank">https://github.com/tvd12/ezyfox-server-example/tree/master/message-stresstest</a></li> <li>Làm sao để chúng ta biết được là server có thể chịu bao nhiêu player login hay call API? và cũng như tính toán số lượng TCP hay UDP tối đa mà server có thể nhận và respone được ạ?</li> <li>Nếu mà chỉ test mỗi phần login thì chắc em chỉ cần trả phần message cho respone biết được là nó đã trả về bao nhiêu message của TCP hoặc là UDP phải k anh?</li> </ol> <p> Em cám ơn anh ạ. </p>
Answer
Avatar
1
Manh Cuong Beginner
Manh Cuong Beginner
Lỗi khi run các example
Mình chạy thử một số example cho game thì đều bị báo lỗi kiểu như dưới đây, bạn check giúp xem tại sao với? <pre> 2022-12-12 12:07:29.555 [main] ERROR c.tvd12.ezyfoxserver.EzyAppsStarter can not start app: one-two-three java.lang.IllegalStateException: can not build writer for class class com.tvd12.ezyfoxserver.app.response.GameFinishedResponse at com.tvd12.ezyfox.binding.impl.EzyAbstractWriterBuilder.build(EzyAbstractWriterBuilder.java:28) at com.tvd12.ezyfox.binding.impl.EzySimpleBindingContext$Builder.parseObjectBindingClass(EzySimpleBindingContext.java:316) at com.tvd12.ezyfox.binding.impl.EzySimpleBindingContext$Builder.parseObjectBindingClasses(EzySimpleBindingContext.java:303) at com.tvd12.ezyfox.binding.impl.EzySimpleBindingContext$Builder.build(EzySimpleBindingContext.java:285) at com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry.createBindingContext(EzySimpleAppEntry.java:135) at com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry.createBeanContext(EzySimpleAppEntry.java:89) at com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry.config(EzySimpleAppEntry.java:47) </pre>
Answer
Avatar
1
Mathis Favier Beginner
Mathis Favier Beginner
[Easyfox-server] null pointer Exception on user repo while trying to connect
So I watched the <a href="https://www.youtube.com/watch?v=aTZDSiiITBM&amp;list=PLlZavoxtKE1IfKY7ohkLLyv6YkHMkvH6G&amp;index=4">video</a> for the authentication with Ezyfox-server but I got an NullPointerException on UserRepo while I try to log in. I can't figure out why because I triple check my code and the video... <p> </p> <p> Here is my code: </p> <p> </p> <pre> # entity/BullyUser: @Getter @Setter @ToString @EzyCollection public class BullyUser { @EzyId int id; String username; String password; } # repo/BullyUserRepo: @EzyRepository("userRepo") public interface BullyUserRepo extends EzyMongoRepository&lt;Long, BullyUser&gt; { } # service/BullyUserService: public interface BullyUserService { void saveUser(BullyUser user); BullyUser createUser(String username, String password); BullyUser getUser(String username); } # service/impl/BullyUserServiceImpl: @Setter @EzySingleton("userService") public class BullyUserServiceImpl implements BullyUserService { @EzyAutoBind private BullyUserRepo BullyUserRepo; @Override public void saveUser(BullyUser user) { BullyUserRepo.save(user); } @Override public BullyUser createUser(String username, String password) { BullyUser user = new BullyUser(); user.setUsername(username); user.setPassword(password); BullyUserRepo.save(user); return user; } @Override public BullyUser getUser(String username) { return BullyUserRepo.findByField("username", username); } } // [PLUGIN]/controller/UserLoginController @EzySingleton @EzyEventHandler(USER_LOGIN) public class UserLoginController extends EzyAbstractPluginEventController { @EzyAutoBind private WelcomeService welcomeService; @EzyAutoBind private BullyUserService userService; @Override public void handle(EzyPluginContext ctx, EzyUserLoginEvent event) { logger.info("{} login in", welcomeService.welcome(event.getUsername())); String username = event.getUsername(); String password = event.getPassword(); BullyUser user = userService.getUser(username); if (user == null) { logger.info("User {} does not exist, creating new user", username); user = userService.createUser(username, password); userService.saveUser(user); } } } </pre>
Answer
Avatar
1
MisYuy Beginner
MisYuy Beginner
Cannot access to local IP address 127.0.0.1
Em là newbie sử dụng Ezyfox Server. Em có test thử băng IP local nhưng liên tục gặp lỗi này ạ! <p> </p> <img class="alignnone size-full wp-image-7908" src="https://stackask.com/wp-content/uploads/2022/10/error.png" alt="" />
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
EzyFox Server: Bắt sự kiện khi một trong những user trong App ngắt kết nối
a ơi, e đang định làm một cái handle để bắt sự kiện khi một trong những user trong App ngắt kết nối thì thông báo tới tất cả user khác trong App, thì e cần dùng cách nào á a
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
EzyFox Server: Lưu thông tin vào AppContext
Những List với class e tự viết thì để lưu data vào, sau đó truy xuất ra trả về cho người chơi thì ntn á a? Concept n là như này, mỗi lần người chơi mới join vào App, thì e cần lưu thông tin về Avatar ID , PlayfabId,... của người chơi đó, thì e sẽ viết một class chứa các thông tin đó, sau đó sẽ có một List ở mỗi app với kiểu là class e vừa viết
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
EzyFox Server: Lấy danh sách user của tất cả các App khi xử lý request từ 1 app bất kỳ
EzyFox Server: Lấy danh sách user của tất cả các App khi xử lý request từ 1 app bất kỳ
Answer