Пример #1
0
        public static void Example4()
        {
            var srv           = new UNetServer();
            var mainChannel   = srv.CreateChannel <TcpServerChannel, StandardPacketProcessor>();
            var secondChannel = srv.CreateChannel <TcpServerChannel, StandardPacketProcessor>();

            mainChannel.OnPeerConnected += (sender, e) => srv.AddPeerToChannel(secondChannel, p => p.Identity.Equals(e.Peer.Identity));

            secondChannel.OnPeerConnected += (sender, e) =>
            {
                secondChannel.OnPacketReceived += (sender2, e2) =>
                {
                    if (e2.Packet.PacketId == 1)
                    {
                        Console.WriteLine("Received ping packet from {0} @ second channel", e2.Peer.Identity.Guid);
                    }
                };
                Console.WriteLine("Peer has connected to second channel");
                secondChannel.Send(new PingPacket(), e.Peer.Identity.Guid);
            };


            srv.Initialize(mainChannel);
            srv.AddChannel(secondChannel);

            Console.ReadLine();
        }
Пример #2
0
        public static void Example3()
        {
            var srv           = new UNetServer();
            var mainChannel   = srv.CreateChannel <TcpServerChannel>();
            var secondChannel = srv.CreateChannel <TcpServerChannel>();


            //mainChannel.OnPeerConnected += (sender, e) =>
            //{
            //    _operations.Add(mainChannel.RegisterOperation<FileTransferOperation>(e.Peer.Identity.Guid));
            //    srv.AddPeerToChannel(secondChannel, p => p.Identity.Guid == e.Peer.Identity.Guid);
            //    count++;
            //    Console.WriteLine("Main channel connect");
            //};
            //secondChannel.OnPeerConnected += (sender, e) =>
            //{
            //    _operations.Add(secondChannel.RegisterOperation<FileTransferOperation>(e.Peer.Identity.Guid));
            //    count++;
            //    Console.WriteLine("second channel connect");
            //};
            //secondChannel.OnPacketReceived += (sender, e) =>
            //{
            //    Console.WriteLine("Received pingpacket from peer: {0} @ channel {1}", e.Peer.Identity.Guid, e.Channel.Id);
            //};

            srv.Initialize(mainChannel);
            srv.AddChannel(secondChannel);

            while (count != 2)
            {
                Thread.Sleep(100);
            }


            _operations[1].SendPacket(new FileTransferInitiatePacket());
            Console.ReadLine();
        }