コード例 #1
0
        public IEnumerator SendToAll()
        {
            Action <WovenTestMessage> func = Substitute.For <Action <WovenTestMessage> >();

            connectionToServer.RegisterHandler(func);

            server.SendToAll(message);

            _ = connectionToServer.ProcessMessagesAsync();

            yield return(null);

            func.Received().Invoke(
                Arg.Is <WovenTestMessage>(msg => msg.Equals(message)
                                          ));
        }
コード例 #2
0
        async Task ConnectionAcceptedAsync(INetworkConnection conn)
        {
            if (logger.LogEnabled())
            {
                logger.Log("Server accepted client:" + conn);
            }

            // are more connections allowed? if not, kick
            // (it's easier to handle this in Mirror, so Transports can have
            //  less code and third party transport might not do that anyway)
            // (this way we could also send a custom 'tooFull' message later,
            //  Transport can't do that)
            if (connections.Count >= MaxConnections)
            {
                conn.Disconnect();
                if (logger.LogEnabled())
                {
                    logger.Log("Server full, kicked client:" + conn);
                }
                return;
            }

            // add connection
            AddConnection(conn);

            // let everyone know we just accepted a connection
            Connected.Invoke(conn);

            // now process messages until the connection closes

            try
            {
                await conn.ProcessMessagesAsync();
            }
            catch (Exception ex)
            {
                logger.LogException(ex);
            }
            finally
            {
                OnDisconnected(conn);
            }
        }