示例#1
0
        protected void StartSocket()
        {
            #region Provider
            if (Players.TryAdd(0, PlayerHelper.MakeTheServerPlayer()))
            {
                for (int i = 0; i < NeutronModule.Settings.GlobalSettings.MaxPlayers; i++)
                {
                    int id = (NeutronConstants.GENERATE_PLAYER_ID + i) + 1;
                    if (Players.TryAdd(id, new NeutronPlayer()
                    {
                        Id = id,
                        Nickname = $"Client#{id}"
                    }))
                    {
                    }
                }
            }
            #endregion

            int port = SocketHelper.GetFreePort(Protocol.Tcp);
            TcpClient = new TcpClient(new IPEndPoint(IPAddress.Any, port));
            UdpClient = new UdpClient(new IPEndPoint(IPAddress.Any, port));

#if UNITY_EDITOR
            Application.quitting += OnQuit;
#endif
        }