unified udp and tcp ports into one

This commit is contained in:
2026-04-05 19:39:29 -03:00
parent 1bc0ae71bf
commit 4bbc65c528
7 changed files with 11 additions and 20 deletions

View File

@@ -2,6 +2,5 @@ package io.github.eldek0.config;
public class ClientConfig {
public String serverIP;
public int udpPort;
public int tcpPort;
public int port;
}

View File

@@ -17,8 +17,7 @@ public class GameClient {
private final Client client;
private final Map<Integer, NetworkPackets.PlayerState> players = new ConcurrentHashMap<>();
private int myId = -1;
private int udpPort = Network.DEFAULT_UDP_PORT;
private int tcpPort = Network.DEFAULT_TCP_PORT;
private int port = Network.DEFAULT_PORT;
private String serverIP;
public GameClient() {
@@ -68,7 +67,7 @@ public class GameClient {
public void connect(String name) throws IOException {
client.start();
client.connect(5000, this.serverIP, this.tcpPort, this.udpPort);
client.connect(5000, this.serverIP, this.port, this.port);
NetworkPackets.Login login = new NetworkPackets.Login();
login.name = name;
@@ -106,8 +105,7 @@ public class GameClient {
ClientConfig config = null;
try {
config = new Gson().fromJson(new FileReader("client-config.json"), ClientConfig.class);
this.udpPort = config.udpPort;
this.tcpPort = config.tcpPort;
this.port = config.port;
this.serverIP = config.serverIP;
} catch (FileNotFoundException e) {
throw new RuntimeException(e);

View File

@@ -5,8 +5,7 @@ import com.esotericsoftware.kryonet.EndPoint;
import java.util.ArrayList;
public class Network {
public static final int DEFAULT_TCP_PORT = 54555;
public static final int DEFAULT_UDP_PORT = 54777;
public static final int DEFAULT_PORT = 54555;
public static void register(EndPoint endPoint) {
Kryo kryo = endPoint.getKryo();