Kryonet on Android device

89 views
Skip to first unread message

ChristopheD

unread,
Jan 29, 2020, 8:31:55 AM1/29/20
to kryonet-users
Hello everybody,
I'm trying to develop a client/server application with kryonet, but i can't manage to make it working on android device. I did exactly what is said on https://github.com/EsotericSoftware/kryonet. It's working fine on desktop device between two PC on the same local network, but i have no result on android device.

My Server
 
        server = new Server();
        Kryo kryo = server.getKryo();
        kryo.register(RqClass.class);
        kryo.register(RpClass.class);
        server.start();
        try {
            server.bind(54555, 54777);
        }
        catch(java.io.IOException e){System.out.println(e.getMessage());}

        server.addListener(new Listener() {
            public void received (Connection connection, Object object) {
                if (object instanceof RqClass) {
                    RqClass request = (RqClass)object;
                    receiveMessage(request.text);
                    sendMessage(connection,"envoyé");
                };;
            }
        });


My Client

        client = new Client();
        Kryo kryo = client.getKryo();
        kryo.register(NetModule.RqClass.class);
        kryo.register(NetModule.RpClass.class);
        client.start();

        InetAddress address = client.discoverHost(54777, 5000);
        if (address==null){
            textArea.appendText("\nServeur introuvable");
            return;
        }
        System.out.println(address);

        try {
            client.connect(5000, address, 54555, 54777);
        }
        catch(java.io.IOException e){
            System.out.println(e.getMessage());
        }
        client.addListener(new Listener() {
            public void received (Connection connection, Object object) {
                if (object instanceof RpClass) {
                    RpClass reply = (RpClass)object;
                    receiveMessage(reply.text);
                }
            }
        });


And I gave the permission in the AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


But the Client.discoverHost() method give a 'Host discovery timed out' message, the application can't find the running server. No more exception message.
It doesn't work even if I mention the local IP of the PC wich is running the Server, even if I use the '127.0.0.1' address instead of using discoverHost(). Because I test it on the same computer.
I tried to disable my firewal, no way.

I found a lot of similar issues on the net, but no solution.

Does someone managed to make kryonet work ? And how ? What did I forget ? Is my Android version in cause ?

    buildToolsVersion "29.0.2"
    compileSdkVersion 29
...
        minSdkVersion 14
        targetSdkVersion 29    (I tried with 26)


I use the 2.22.0-RC1 version of kryonet.

Thanks a lot for your help.
Reply all
Reply to author
Forward
0 new messages