Kryonet - 'client.connect()' is stuck, has to be launched twice

Hello. I’m using Kryonet. After updating Android to 5.0, there were some changes, that broke Kryonet. Smart guys had to write a patch, cause UDP were not working etc.

Now, I’m experiencing a strange issue. Let’s say that I have a class like this (made it for testing):

public class Test {
    public static String host = "xxxxxx";
    // public static String host = "192.168.1.2";
    public static int tcp_port = 8888, udp_port = 8889;
    Client c;

    public Test() {
         c = new Client();
        c.start();
        Network.register(c);
    }

    public void tryToConnect(){
        new Thread("Connect") {
            public void run () {
                try {
                    System.out.println("Before");
                    c.connect(5555, host, tcp_port, udp_port);
                    System.out.println("After");
                    // Server communication after connection can go here, or in Listener#connected().
                } catch (IOException ex) {
                    ex.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }
}

In main class I have a button that runs tryToConnect():

  protected void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        Log.set(Log.LEVEL_TRACE);
        t = new Test();
    }


 public void Login(View view) { // <<<<< This is the button onClick
         t.tryToConnect();
    }

I have already tried with running all of this in one block (registering client, connecting) - the same thing happens.

What’s the problem?

I open the APP (log level trace) and I can see, that Network.register© is fired, cause I see all of the 46 classes registering.
When I click the button and fire ‘client.connect(timeout,ip,port,port)’ nothing happens. Totally nothing. The console is empty (but the method has been runned), cause I have Sys.out(“Before”) and Sys.out(“After”) - as you can see in the code. ‘Before’ is in the console, ‘After’ isn’t. And the best part. When I click second time, IT CONNECTS, but twice. There is an info like:

[Kryo] Connecting with blabla on port blabla
[Kryo] Connecting with blabla on port blabla

What may cause this? I’m sitting here for 6 hours and I have tried everything already. Thanks.

Caused by their latest ‘unconfirmed’ fix. Sorry guys!

Caused by wut?

Arr, NOT THEIR FIX, it was a fix from a random guy. I thought that he’s in your crew :smiley:

Btw, the fix for Android >5.0 that the guy posted on github (desertkun) is causing other bugs.

I’m sorry. And much respect for creating Kryonet - saved my life :slight_smile: