Пример #1
0
 public PeerDisconnectedEventArgs(Peer peer, string reason)
     : base(peer)
 {
     DisconnectReason = reason;
 }
Пример #2
0
 public PeerConnectedEventArgs(Peer peer)
     : base(peer)
 {
 }
Пример #3
0
 public PeerEventArgs(Peer peer)
 {
     Peer = peer;
 }
Пример #4
0
 public PacketEventArgs(Peer peer, IPacket packet, int rawPacketSize)
 {
     SourcePeer = peer;
     Packet = packet;
     RawPacketSize = rawPacketSize;
 }
Пример #5
0
        private async void AcceptAsync()
        {
            while (true)
            {
                var client = await _uNetSock.AcceptTcpClientAsync();
                var peer = new Peer(client, this, Settings);

                //Subscribe to peer events
                peer.OnPeerDisconnected += PeerDisconnect;
                peer.OnPacketReceived += (o, e) => { if(OnPacketReceived != null) { OnPacketReceived(o, e); } };
                peer.InternalOnPacketReceived += InternalOnPacketReceived;
                peer.Processor.OnPacketSent += (o, e) => { if (OnPacketSent != null) { OnPacketSent(null, new PacketEventArgs(null, e.Packet, e.RawPacketSize)); } }; 

                ConnectedPeers.Add(peer);

                if (_debug)
                    Debug.Print("Peer connected from: " + peer.RemoteEndPoint);

                if (OnPeerConnected != null)
                    OnPeerConnected(null, new PeerConnectedEventArgs(peer));
            }
        }