Beispiel #1
0
        public void testReader()
        {
            G2Network.Instance.SelfAddress = System.Net.IPAddress.Parse("127.0.0.1");
            G2Packet lni = Settings.SmartLNIPacket();
            G2Packet na  = new G2PacketNA(new NodeAddress(System.Net.IPAddress.Parse("127.0.0.1"), 6345));

            for (int i = 0; i < 300; i++)
            {
                lni.AddChild(na);
            }
            lni.FinalizePacket();
            G2Log.Write(lni.ToString());
            ByteBuffer     b      = lni.ToBuffer();
            G2PacketReader reader = new G2PacketReader(new NodePeer(System.Net.IPAddress.Parse("127.0.0.1"), 6346, 0, false));
            int            nb     = 3;

            byte[][] bytes = new byte[nb][];
            int      start = 0;
            int      div   = b.Length / nb;

            for (int i = 0; i < nb; i++)
            {
                if (i == nb - 1)
                {
                    div += b.Length % nb;
                }
                bytes [i] = new byte[div];
                Array.Copy(b.Bytes, start, bytes [i], 0, div);
                start += div;
            }


            for (int i = 0; i < nb; i++)
            {
                bool enough = reader.Read(bytes [i], bytes[i].Length);
                if (enough)
                {
                    G2Log.Write("PacketReader Test Success");
                    break;
                }
            }
            G2Packet   lni2 = Settings.SmartLNIPacket();
            ByteBuffer b2   = lni2.ToBuffer();
            bool       succ = reader.Read(b2.Bytes, b2.DataOffset);

            if (succ)
            {
                G2Log.Write("PacketReader Test Unit Packet Success");
            }
            else
            {
                G2Log.Write("PacketReader Test Unit Packet FAILED");
            }


            b.Append(b2);
            succ = reader.Read(b.Bytes, b.DataOffset);
            if (succ)
            {
                G2Log.Write("PacketReader Test Sequential Packet Success");
            }
            else
            {
                G2Log.Write("PacketReader TEst Sequential Packet FAILED");
            }
        }
Beispiel #2
0
 public void SendPacket(G2Packet pack)
 {
     pack.FinalizePacket();
     pack.RemotePeer = this;
     Buffer.PushPacketToSend(pack);
 }