Пример #1
0
        public override void ServerStart()
        {
            m_Server?.Dispose();

            ServerConfig config;

            if (!string.IsNullOrWhiteSpace(m_RsaXmlPath))
            {
                var xml = Resources.Load <TextAsset>(m_RsaXmlPath);
                config = ServerConfig.FromXML(xml.text, m_Port);
            }
            else
            {
                config = ServerConfig.Create(m_Port);
            }
            m_Server              = Connection.StartServer(config);
            m_Server.OnPeerEvent += (e) =>
            {
                switch (e.EventType)
                {
                case PeerEvent.Type.Add:
                    OnServerConnected?.Invoke(Mathf.Abs(e.Peer.ConnectionId));
                    break;

                case PeerEvent.Type.Remove:
                    OnServerDisconnected?.Invoke(Mathf.Abs(e.Peer.ConnectionId));
                    break;
                }
            };
        }
Пример #2
0
        void Awake()
        {
            Log.Init();
            Log.Level = Log.LogLevel.Trace;
            var config = ServerConfig.FromXML(Resources.Load <TextAsset>("private").text, Port);

            m_Server = Connection.StartServer(config);
            Connect();
        }
Пример #3
0
        public override SocketTasks StartServer()
        {
            ServerConfig config;

            if (!string.IsNullOrWhiteSpace(m_RsaXmlPath))
            {
                var xml = Resources.Load <TextAsset>(m_RsaXmlPath);
                config = ServerConfig.FromXML(xml.text, m_Port);
            }
            else
            {
                config = ServerConfig.Create(m_Port);
            }
            m_Server = Connection.StartServer(config);
            Setup(m_Server);
            return(SocketTask.Done.AsTasks());
        }