I’m in the process of making a base for my networking in my Unity game. I’m not a very experienced C# coder and have been learning things on the fly as I need them: occasionally I run into bigger problems like this one! I’m a bit stumped as to the best way to store my connections/connectionInfo.
At the moment my solution was to make a custom class that I’m populating with the “Connection” and various other unrelated variables such as the player name, player ID and other game related “per connection/player” things as they become available. This makes it extremely easy to cycle through players and grab information quickly as required on the fly. The networkidentifier on each connectionInfo is particularly useful to me for linking each packet easily to each player.
The very big problem I’m running into is that when I store the connection like that, I suspect that I’m simply making a copy of the connection object at the time of storage. That means that I can’t do vital things like check connectionState. I’m probably going about it wrong.
Is there an easy (and more importantly, a quick) way to cycle through all existing connections and be able to identify them by their NetworkIdentifers (or some other method)?
Not sure how useful this would be but: simplified version of how my server/client program works is this:
- Server starts listening on UDP
- Client sends UDP packet to server (with handshake)
- Server sends UDP packet back to the client requesting some info
- Client sends UDP packet with that info
- Server registers the info in the custom class, storing the (by now populated) unique network identifier
Apologies in advance for the newbie question, but truly a bit stumped on this simple hurdle!
Sorry for the slow reply. You could do the following:
//Get a list of all existing connections, please see the many overrides to getting different groups of connection
List<Connection> connections = NetworkComms.GetExistingConnection(ConnectionType.UDP);
foreach (Connection conn in connections)
//Do work using conn