Question

I try to use Kryonet to create an online game.

When I give the ip adress (hardcoded in the code), connection and sendind/receiving works. But if I try to discover the server, It's never responding me: the method always return null.

Server:

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());
}

Client:

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();
}

What's wrong in this code? Note that my tests are launched on localhost. Is it a problem here ?

Thank's for all reponse.

Jonathan

Was it helpful?

Solution

If you are having the same problem I had related to discover hosts (http://code.google.com/p/kryonet/issues/detail?id=29) then checking out the project from SVN (instead of using the 2.20 zip file) fixed the issue for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top