示例#1
0
    protected override void OnUpdate()
    {
        if (!m_ServerDriverSystem.ServerDriver.IsCreated)
        {
            return;
        }
        var driver = m_ServerDriverSystem.ConcurrentServerDriver;

        Entities.ForEach((ref PingServerConnectionComponentData connection) =>
        {
            DataStreamReader strm;
            NetworkEvent.Type cmd;
            while ((cmd = driver.PopEventForConnection(connection.connection, out strm)) != NetworkEvent.Type.Empty)
            {
                if (cmd == NetworkEvent.Type.Data)
                {
                    int id       = strm.ReadInt();
                    var pongData = driver.BeginSend(connection.connection);
                    pongData.WriteInt(id);
                    driver.EndSend(pongData);
                }
                else if (cmd == NetworkEvent.Type.Disconnect)
                {
                    connection = new PingServerConnectionComponentData {
                        connection = default(NetworkConnection)
                    };
                }
            }
        }).ScheduleParallel();
    }
示例#2
0
        public void Execute(int i)
        {
            DataStreamReader strm;

            NetworkEvent.Type cmd;
            while ((cmd = driver.PopEventForConnection(connections[i].connection, out strm)) != NetworkEvent.Type.Empty)
            {
                if (cmd == NetworkEvent.Type.Data)
                {
                    var readerCtx = default(DataStreamReader.Context);
                    int id        = strm.ReadInt(ref readerCtx);
                    var pongData  = new DataStreamWriter(4, Allocator.Temp);
                    pongData.Write(id);
                    driver.Send(connections[i].connection, pongData);
                    pongData.Dispose();
                }
                else if (cmd == NetworkEvent.Type.Disconnect)
                {
                    connections[i] = new PingServerConnectionComponentData {
                        connection = default(NetworkConnection)
                    };
                }
            }
        }