Beispiel #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
        }
Beispiel #2
0
        public void StopServer()
        {
#if !UNITY_WEBGL || UNITY_EDITOR
            if (wsServer != null)
            {
                wsServer.Dispose();
            }
            if (wssServer != null)
            {
                wssServer.Dispose();
            }
            wsServer         = null;
            wssServer        = null;
            nextConnectionId = 1;
#endif
        }
        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
        }
        public void StopServer()
        {
#if !UNITY_WEBGL
            if (wsServer != null)
            {
                wsServer.Dispose();
            }
            if (wssServer != null)
            {
                wssServer.Dispose();
            }
            wsServer  = null;
            wssServer = null;
            if (Server != null)
            {
                Server.Stop();
            }
            Server           = null;
            nextConnectionId = 1;
#endif
        }
 public WssTransportSession(long connectionId, WssTransportServer server) : base(server)
 {
     ConnectionId = connectionId;
     _server      = server;
 }