英文:
Separate main() methods to run DesktopLauncher.main() and Server using Libgdx and Kryonet
问题
I want my GameServer to run separately from the game itself. So, players(clients) can join into one static GameServer and I can handle them together and see how many clients are connected, currently.
But the problem is, I can only run only one of these classes(GameServer.main() and DesktopLauncher.main()) at the same time. GameServer must be running always at the background if I'm not wrong, right ? Yet, I can't run the game itself without stopping the GameServer. (It stucks saying Executing task 'DesktopLauncher.main()'...) I have some pictures to realize what's going on and what project structure looks like :
Here is my project structure :
core
-java
--com.mygdx.game
---Multiplayer
----Packets
-----GameClient.java
-----GameServer.java
-----GameClientListener.java
-----GameServerListener.java
---screens
---utils
---Application.java
GameServer.class
package com.mygdx.game.Multiplayer;
imports..
public class GameServer {
public int TCP_PORT,UDP_PORT;
public Server server;
public GameServerListener listener;
public static int totalClients = 0;
public GameServer() {
TCP_PORT = UDP_PORT = xxxx;
server = new Server(TCP_PORT,UDP_PORT);
listener = new GameServerListener(this);
startServer();
}
public void startServer() {
server.addListener(listener);
try {
server.bind(TCP_PORT,UDP_PORT);
//server.bind(TCP_PORT);
} catch (IOException e) {
e.printStackTrace();
}
registerPackets();
server.start();
}
private void registerPackets() {
server.getKryo().register(LoginRequest.class);
server.getKryo().register(LoginResponse.class);
server.getKryo().register(ChoiceRequest.class);
server.getKryo().register(ChoiceRespond.class);
}
public static void main(String[] args) {
new GameServer();
}
}
Thanks for any help.
英文:
I want my GameServer to run separately from the game itself. So, players(clients) can join into one static GameServer and I can handle them together and see how many clients are connected, currently.
But the problem is, I can only run only one of these classes(GameServer.main() and DesktopLauncher.main()) at the same time. GameServer must be running always at the background if I'm not wrong, right ? Yet, I can't run the game itself without stopping the GameServer. (It stucks saying Executing task 'DesktopLauncher.main()'...) I have some pictures to realize what's going on and what project structure looks like :
Here is my project structure :
> core
> -java
> --com.mygdx.game
> ---Multiplayer
> ----Packets
> -----GameClient.java
> -----GameServer.java
> -----GameClientListener.java
> -----GameServerListener.java
> ---screens
> ---utils
> ---Application.java
GameServer.class
package com.mygdx.game.Multiplayer;
imports..
public class GameServer {
public int TCP_PORT,UDP_PORT;
public Server server;
public GameServerListener listener;
public static int totalClients = 0;
public GameServer() {
TCP_PORT = UDP_PORT = xxxx;
server = new Server(TCP_PORT,UDP_PORT);
listener = new GameServerListener(this);
startServer();
}
public void startServer() {
server.addListener(listener);
try {
server.bind(TCP_PORT,UDP_PORT);
//server.bind(TCP_PORT);
} catch (IOException e) {
e.printStackTrace();
}
registerPackets();
server.start();
}
private void registerPackets() {
server.getKryo().register(LoginRequest.class);
server.getKryo().register(LoginResponse.class);
server.getKryo().register(ChoiceRequest.class);
server.getKryo().register(ChoiceRespond.class);
}
public static void main(String[] args) {
new GameServer();
}
}
Thanks for any help.
答案1
得分: 0
降级到 Android Studio 3.4 对我有效。
查看:https://www.reddit.com/r/libgdx/comments/fxrlsm/unable_to_run_two_or_more_application_in_parallel/
英文:
Had the same issue. Downgrading to Android Studio 3.4 worked for me.
Check: https://www.reddit.com/r/libgdx/comments/fxrlsm/unable_to_run_two_or_more_application_in_parallel/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论