Search code examples
javalibgdxkryonet

Kryonet connection ID limit?


I'm using kryonet for my LibGDX project. Every time a client connects to the server, a new connection ID gets created. Eg. Client 1: ID 1. Client 2: ID 2.

When a client reconnects, the counter continues, it does not seem to reuse older IDs. Eg. Client 1 reconnects: ID 3.

Does kryonet reset the counter after a while? Or is there any way to reset the counter? I'm worried about running into issues after my server has been running for a little while.


Solution

  • I have solved my own problem but I will leave it here if anyone is interested.

    I was looking through the source of Kryonet and found this:

    int id = nextConnectionID++;
    if (nextConnectionID == -1) nextConnectionID = 1;
    

    When this value reaches the maximum value, it flips to the minimum value. Ref: https://stackoverflow.com/a/5131206/4697327 .

    I guess there will never be a problem.

    EDIT: Kryonet uses -1 as ID when the Connection has never been made. If the nextConnectionID counts up to 32 bits max value, then flips to it's minimum value and counts up to 0 again, it will pass -1 at some point. This will be a problem for one connection. I haven't found a problem with negative ID's yet.