Esempio n. 1
0
 static void PeerOnConnectionSuccessful(object sender, ConnectionAcceptedEventArgs e)
 {
     Console.WriteLine();
     Console.WriteLine("Requesting to register with the Introducer...");
     IntroducerSocket.Send(new RequestIntroducerRegistrationMessage()
     {
         InternalClientEndPoint = (IPEndPoint)e.Socket.LocalEndPoint
     });
 }
Esempio n. 2
0
        static void Peer_OnMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            switch (e.MessageType)
            {
            case MessageType.ResponseIntroducerRegistration:
            {
                var message = new ResponseIntroducerRegistrationMessage();
                message.ReadPayload(e.MessageReader);

                Console.WriteLine(String.Format("Introducer: You have been registered as \"{0}\".", message.RegisteredEndPoint));

                Console.Write("Endpoint of your peer: ");

                var peerEndPoint = Console.ReadLine().Parse();

                Console.WriteLine(String.Format("Requesting an introduction to {0}:{1}...", peerEndPoint.Address, peerEndPoint.Port));
                IntroducerSocket.Send(new RequestIntroducerIntroductionMessage()
                    {
                        InternalOwnEndPoint = (IPEndPoint)IntroducerSocket.Socket.LocalEndPoint, ExternalPeerEndPoint = peerEndPoint
                    });
            }
            break;

            case MessageType.ResponseIntroducerIntroduction:
            {
                var message = new ResponseIntroducerIntroductionMessage();
                message.ReadPayload(e.MessageReader);

                Console.WriteLine(String.Format("Introducer: Your peer's internal endpoint is \"{0}\".", message.InternalPeerEndPoint));
                Console.WriteLine(String.Format("Introducer: Your peer's external endpoint is \"{0}\".", message.ExternalPeerEndPoint));

                ConnectSocketInternal = new NetworkPeer();
                ConnectSocketInternal.Bind(new IPEndPoint(IPAddress.Any, PORT));
                Console.WriteLine(String.Format("Connecting to your peer's internal endpoint..."));
                ConnectSocketInternal.OnConnectionSuccessful += (s, e1) => Console.WriteLine("ConnectSocketInternal.OnConnectionSuccessful");
                ConnectSocketInternal.Connect(message.InternalPeerEndPoint.Address, message.InternalPeerEndPoint.Port);

                ConnectSocketExternal = new NetworkPeer();
                ConnectSocketExternal.Bind(new IPEndPoint(IPAddress.Any, PORT));
                Console.WriteLine(String.Format("Connecting to your peer's external endpoint..."));
                ConnectSocketExternal.OnConnectionSuccessful += (s, e1) => Console.WriteLine("ConnectSocketExternal.OnConnectionSuccessful");
                ConnectSocketExternal.Connect(message.ExternalPeerEndPoint.Address, message.ExternalPeerEndPoint.Port);
            }
            break;
            }
        }