Client NetworkConnection ID always 0

Hello everyone, I’m using a basic example of a client and server using the transport layer, I’m curious why the NetworkConnection we get during _driver.Connect(endPoint); always has id 0?

At the same time, on the server, when a new client connects, I get the correct new id, but on the client it is always 0. Am I doing something wrong? is this the correct behavior? How can I get the correct id on the client side when connecting? Any help would be greatly appreciated!

This is the expected behavior. Connection IDs are not symmetric on the client and server. That is, the IDs may not match on both ends. These IDs are not meant to uniquely identify connections across endpoints, they’re meant to identify connections at the driver level.

One way to think about it is that these IDs are how individual NetworkDriver objects see the connections. The first connection made by a driver is always ID 0, and the next one is 1, etc. So for your clients they’re all going to have ID 0, whereas the server will see IDs 0, 1, 2, and so on. The numerical value shouldn’t be taken as meaning anything. It’s basically an internal identifier for the driver.

If you need to uniquely identify connections (e.g. know which connection belongs to which client), I suggest having the client send a unique identifier when it connects (say a user ID or an authentication token). Starting with version 2.2 of the Unity Transport package, you can send an arbitrary payload with connection requests that makes this relatively easy to implement. Netcode solutions (like Netcode for GameObjects) usually have some form of connection approval mechanism that can serve the same purpose.

Thanks for your detailed answer!