diff --git a/Unity-Technologies-networking/Runtime/Telepathy/Common.cs b/Unity-Technologies-networking/Runtime/Telepathy/Common.cs index 5ad389b3b..b05928327 100644 --- a/Unity-Technologies-networking/Runtime/Telepathy/Common.cs +++ b/Unity-Technologies-networking/Runtime/Telepathy/Common.cs @@ -7,12 +7,6 @@ namespace Telepathy public abstract class Common { // common code ///////////////////////////////////////////////////////// - // connectionId counter - // (right now we only use it from one listener thread, but we might have - // multiple threads later in case of WebSockets etc.) - // -> static so that another server instance doesn't start at 0 again. - protected static SafeCounter counter = new SafeCounter(); - // incoming message queue of // (not a HashSet because one connection can have multiple new messages) protected SafeQueue messageQueue = new SafeQueue(); diff --git a/Unity-Technologies-networking/Runtime/Telepathy/Server.cs b/Unity-Technologies-networking/Runtime/Telepathy/Server.cs index ae7c552ae..5e5ad8c44 100644 --- a/Unity-Technologies-networking/Runtime/Telepathy/Server.cs +++ b/Unity-Technologies-networking/Runtime/Telepathy/Server.cs @@ -15,6 +15,20 @@ public class Server : Common // clients with SafeDictionary clients = new SafeDictionary(); + // connectionId counter + // (right now we only use it from one listener thread, but we might have + // multiple threads later in case of WebSockets etc.) + // -> static so that another server instance doesn't start at 0 again. + static SafeCounter counter = new SafeCounter(); + + // public next id function in case someone needs to reserve an id + // (e.g. if hostMode should always have 0 connection and external + // connections should start at 1, etc.) + public static uint NextConnectionId() + { + return counter.Next(); + } + // check if the server is running public bool Active { @@ -45,7 +59,7 @@ void Listen(int port) TcpClient client = listener.AcceptTcpClient(); // generate the next connection id (thread safely) - uint connectionId = counter.Next(); + uint connectionId = NextConnectionId(); // spawn a thread for each client to listen to his // messages