Пример #1
0
    public SoakClient(double sendInterval, int packetSize, int duration)
    {
        DriverHandle = NetworkDriver.Create(
            new SimulatorUtility.Parameters
        {
            MaxPacketSize        = packetSize, MaxPacketCount = 30, PacketDelayMs = 25,
            PacketDropPercentage = 10     /*PacketDropInterval = 100*/
        }, new ReliableUtility.Parameters {
            WindowSize = 32
        });
        //Pipeline = DriverHandle.CreatePipeline(typeof(UnreliableSequencedPipelineStage), typeof(SimulatorPipelineStage));
        Pipeline         = DriverHandle.CreatePipeline(typeof(ReliableSequencedPipelineStage), typeof(SimulatorPipelineStage));
        ReliableStageId  = NetworkPipelineStageCollection.GetStageId(typeof(ReliableSequencedPipelineStage));
        SimulatorStageId = NetworkPipelineStageCollection.GetStageId(typeof(SimulatorPipelineStage));
        if (packetSize > NetworkParameterConstants.MTU)
        {
            Debug.LogWarning("Truncating packet size to MTU");
            packetSize = NetworkParameterConstants.MTU;
        }
        else if (packetSize < SoakMessage.HeaderLength)
        {
            Debug.LogWarning("Packet size was to small resizing to at least SoakMessage HeaderSize");
            packetSize = SoakMessage.HeaderLength;
        }

        var payloadSize = packetSize - SoakMessage.HeaderLength;

        PendingSoakMessages = new NativeArray <SoakMessage>(64, Allocator.Persistent);
        ConnectionHandle    = new NativeArray <NetworkConnection>(1, Allocator.Persistent);

        SoakJobDataPacket = new NativeArray <byte>(payloadSize, Allocator.Persistent);
        var    random = new byte[payloadSize];
        Random r      = new Random();

        r.NextBytes(random);
        SoakJobDataPacket.CopyFrom(random);

        SoakJobContextsHandle = new NativeArray <SoakJobContext>(1, Allocator.Persistent);
        var context = new SoakJobContext
        {
            Duration     = duration,
            PacketSize   = packetSize,
            SendInterval = sendInterval
        };

        SoakJobContextsHandle[0] = context;

        SoakStatisticsHandle    = new NativeArray <SoakStatisticsPoint>(2, Allocator.Persistent);
        SoakStatisticsHandle[0] = new SoakStatisticsPoint();
        SoakStatisticsHandle[1] = new SoakStatisticsPoint();
    }
Пример #2
0
    public void Start()
    {
        m_Connections  = new NativeList <SoakClientCtx>(1, Allocator.Persistent);
        m_ServerDriver = NetworkDriver.Create(new ReliableUtility.Parameters {
            WindowSize = 32
        });
        //m_Pipeline = m_ServerDriver.CreatePipeline(typeof(UnreliableSequencedPipelineStage));
        m_Pipeline        = m_ServerDriver.CreatePipeline(typeof(ReliableSequencedPipelineStage));
        m_ReliableStageId = NetworkPipelineStageCollection.GetStageId(typeof(ReliableSequencedPipelineStage));
        var addr = NetworkEndPoint.AnyIpv4;

        addr.Port = 9000;
        if (m_ServerDriver.Bind(addr) != 0)
        {
            Debug.Log("Failed to bind to port 9000");
        }
        else
        {
            m_ServerDriver.Listen();
        }
    }