Esempio n. 1
0
        public bool StartServer(int port, int maxConnections)
        {
#if !UNITY_WEBGL || UNITY_EDITOR
            if (IsServerStarted)
            {
                return(false);
            }
            if (!secure)
            {
                wsServer = new WsTransportServer(this, IPAddress.Any, port, maxConnections);
                wsServer.OptionDualMode = true;
                wsServer.OptionNoDelay  = true;
                return(wsServer.Start());
            }
            else
            {
                SslContext context = new SslContext(SslProtocols.Tls12, new X509Certificate2(certificateFilePath, certificatePassword), CertValidationCallback);
                wssServer = new WssTransportServer(this, context, IPAddress.Any, port, maxConnections);
                wssServer.OptionDualMode = true;
                wssServer.OptionNoDelay  = true;
                return(wssServer.Start());
            }
#else
            return(false);
#endif
        }
Esempio n. 2
0
        public bool StartServer(int port, int maxConnections)
        {
#if UNITY_WEBGL
            // Don't integrate server networking to WebGL clients
            return(false);
#else
            if (IsServerStarted)
            {
                return(false);
            }

            ServerMaxConnections = maxConnections;
            while (serverEventQueue.TryDequeue(out _))
            {
            }

            // Start WebSocket Server
            if (!webSocketSecure)
            {
                wsServer = new WsTransportServer(this, IPAddress.Any, port + webSocketPortOffset, maxConnections);
                wsServer.OptionDualMode = true;
                wsServer.OptionNoDelay  = true;
                if (!wsServer.Start())
                {
                    return(false);
                }
            }
            else
            {
                SslContext context = new SslContext(SslProtocols.Tls12, new X509Certificate2(webSocketCertificateFilePath, webSocketCertificatePassword), CertValidationCallback);
                wssServer = new WssTransportServer(this, context, IPAddress.Any, port + webSocketPortOffset, maxConnections);
                wssServer.OptionDualMode = true;
                wssServer.OptionNoDelay  = true;
                if (!wssServer.Start())
                {
                    return(false);
                }
            }

            // Start LiteNetLib Server
            serverPeers.Clear();
            Server = new NetManager(new MixTransportEventListener(this, serverEventQueue, serverPeers));
            Server.ChannelsCount = serverDataChannelsCount;
            return(Server.Start(port));
#endif
        }