Kryonet:发现主机始终返回 null

问题描述 投票:0回答:1

我尝试使用 Kryonet 来创建一个在线游戏。

当我给出 IP 地址(在代码中硬编码)时,连接和发送/接收就可以工作。

但是,如果我尝试发现服务器,它永远不会响应我:该方法总是返回 null。

服务器:

public static int UDP_PORT = 54723, TCP_PORT = 54722;
public static void main(String args[]) {
   
    /* ***** server starting ***** */
    Server server = new Server();
    server.start();
     
    try {
        server.bind(TCP_PORT, UDP_PORT);
    } catch (IOException e) {
        System.out.println("server not deployed");
        e.printStackTrace();
        System.exit(1);
    }
    System.out.println("server started");
    server.addListener(new ServerListener());
}

客户:

public static void main(String[] args) {
    Client client = new Client();
     
    client.start();
    InetAddress addr = client.discoverHost(UDP_PORT, 10000);
    System.out.println(addr);
    if(addr == null) {
        System.exit(0);
    }
     
    try {
        client.connect(5000, addr, TCP_PORT, UDP_PORT);
    } catch (IOException e) {
        e.printStackTrace();
    }
     
    for(int i = 0; i < 100; i++) {
        client.sendTCP(new String("bouh" + i));
    }
     
    client.close();
}

这段代码有什么问题? 请注意,我的测试是在本地主机上启动的。难道是这里有问题?

感谢大家的回复。

乔纳森

networking udp kryonet device-discovery
1个回答
0
投票

如果您遇到与发现主机相关的相同问题(http://code.google.com/p/kryonet/issues/detail?id=29),请从 SVN 查看该项目(而不是使用2.20 zip 文件)为我解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.