public void Payload() { SocketMessageFactory spawner = SocketMessageFactory.Instance; Package.SocketMessage buffer = spawner.Spawn(); int payloadSize = buffer.GetPayloadBufferSize(); byte[] payloadSource = new byte[payloadSize]; byte[] payloadReaded = new byte[payloadSize]; _BuildPayloadData(payloadSource); buffer.WritePayload(payloadSource, 0, payloadSource.Length); bool ok = buffer.CheckPayload(); Assert.True(ok); ushort payloadLength = buffer.GetPayloadLength(); Assert.Equal((ushort)payloadSize, payloadLength); bool result = buffer.ReadPayload(payloadReaded, 0); Assert.True(result); for (int i = 0; i < payloadLength; ++i) { Assert.Equal((byte)i, payloadReaded[i]); } }
public void Seq() { SocketMessageFactory spawner = SocketMessageFactory.Instance; Package.SocketMessage buffer = spawner.Spawn(); buffer.SetSeq(0x1234); ushort seq = buffer.GetSeq(); Assert.Equal((ushort)0x1234, seq); }
public void Operation() { SocketMessageFactory spawner = SocketMessageFactory.Instance; Package.SocketMessage buffer = spawner.Spawn(); buffer.SetOperation(0x12); byte value = buffer.GetOperation(); Assert.Equal((byte)0x12, value); }
public void AckFields() { SocketMessageFactory spawner = SocketMessageFactory.Instance; Package.SocketMessage buffer = spawner.Spawn(); buffer.SetAckFields(0x12345678u); uint value = buffer.GetAckFields(); Assert.Equal((uint)0x12345678, value); }
public void Ack() { SocketMessageFactory spawner = SocketMessageFactory.Instance; Package.SocketMessage buffer = spawner.Spawn(); buffer.SetAck(0x1234); ushort value = buffer.GetAck(); Assert.Equal((ushort)0x1234, value); }
public void TestFullFlow() { SocketMessageFactory spawner = SocketMessageFactory.Instance; IPEndPoint hostEndpoint = new IPEndPoint(IPAddress.Parse("0.0.0.1"), 0); IPEndPoint agentEndpoint = new IPEndPoint(IPAddress.Parse("0.0.0.2"), 0); FakeSocket hostSocket = new FakeSocket(hostEndpoint); FakeSocket agentSocket = new FakeSocket(agentEndpoint); hostSocket.SendEvent += (pkg) => { Package.SocketMessage package = spawner.Spawn(); package.SetEndPoint(hostEndpoint); Buffer.BlockCopy(pkg.Package, 0, package.Package, 0, pkg.Package.Length); agentSocket.Receive(package); }; agentSocket.SendEvent += (pkg) => { Package.SocketMessage package = spawner.Spawn(); package.SetEndPoint(agentEndpoint); Buffer.BlockCopy(pkg.Package, 0, package.Package, 0, pkg.Package.Length); hostSocket.Receive(package); }; Host host = new Regulus.Network.Host(hostSocket, hostSocket); Agent agent = new Regulus.Network.Agent(agentSocket, agentSocket); Socket clientPeer = agent.Connect(hostEndpoint, (connect_result) => { }); Updater <Timestamp> updater = new Updater <Timestamp>(); updater.Add(hostSocket); updater.Add(agentSocket); updater.Add(host); updater.Add(agent); long ticks = 0; Socket rudpSocket = null; host.AcceptEvent += p => rudpSocket = p; updater.Working(new Timestamp(ticks++, 1)); updater.Working(new Timestamp(ticks++, 1)); updater.Working(new Timestamp(ticks++, 1)); updater.Working(new Timestamp(ticks++, 1)); updater.Working(new Timestamp(ticks++, 1)); updater.Working(new Timestamp(ticks++, 1)); Assert.AreNotEqual(null, rudpSocket); Assert.AreEqual(PeerStatus.Transmission, clientPeer.Status); byte[] sendBuffer = new byte[] { 1, 2, 3, 4, 5 }; clientPeer.Send(sendBuffer, 0, sendBuffer.Length); int readCount = 0; byte[] receivedBuffer = new byte[Config.Default.PackageSize]; Task <int> task = rudpSocket.Receive(receivedBuffer, 0, receivedBuffer.Length); Task waitTask = task.ContinueWith(t => { readCount = t.Result; }); while (readCount == 0) { updater.Working(new Timestamp(ticks++, 1)); } Assert.AreEqual(sendBuffer.Length, readCount); clientPeer.Disconnect(); updater.Working(new Timestamp(ticks++, 1)); updater.Working(new Timestamp(ticks++, 1)); updater.Working(new Timestamp(ticks++, 1)); updater.Working(new Timestamp(ticks++, 1)); Assert.AreEqual(PeerStatus.Close, rudpSocket.Status); }