コード例 #1
0
        static void Main(string[] args)
        {
            Console.Title = "Peer - TCP Hole Punching Proof of Concept";

            ListenSocket = new NetworkPeer();
            ListenSocket.OnConnectionAccepted += (s, e1) => Console.WriteLine("ListenSocket.OnConnectionAccepted");
            ListenSocket.Bind(new IPEndPoint(IPAddress.Any, PORT));
            ListenSocket.Listen();
            Console.WriteLine(String.Format("Listening for clients on {0}...", ListenSocket.Socket.LocalEndPoint));

            IntroducerSocket = new NetworkPeer();
            IntroducerSocket.OnConnectionAccepted += Peer_OnConnectionAccepted;
            IntroducerSocket.OnConnectionSuccessful += PeerOnConnectionSuccessful;
            IntroducerSocket.OnMessageSent += PeerOnMessageSent;
            IntroducerSocket.OnMessageReceived += Peer_OnMessageReceived;

            IntroducerSocket.Bind(new IPEndPoint(IPAddress.Any, PORT));

            Console.Write("Endpoint of the introducer (try 50.18.245.235:1618): ");

            var input = Console.ReadLine();
            input = (String.IsNullOrEmpty(input)) ? "50.18.245.235:1618" : input;
            var introducerEndpoint = input.Parse();

            Console.WriteLine(String.Format("Connecting to the Introducer at {0}:{1}...", introducerEndpoint.Address, introducerEndpoint.Port));
            IntroducerSocket.Connect(introducerEndpoint.Address, introducerEndpoint.Port);

            Application.Run();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.Title = "Ideal Server - TCP Hole Punching Proof of Concept";

            Incoming = new NetworkPeer();

            Incoming.Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
            Incoming.Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

            Console.Write("Incoming: Bind to which port?: ");
            int portToBind = Int32.Parse(Console.ReadLine());
            Incoming.Bind(new IPEndPoint(IPAddress.Any, portToBind));
            Incoming.Listen();

            Console.WriteLine(String.Format("Listening for clients on {0}...", Incoming.Socket.LocalEndPoint));
            Console.ReadLine();

            Outgoing = new NetworkPeer();

            Outgoing.Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
            Outgoing.Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

            Console.Write("Outgoing: Bind to which port?: ");
            Outgoing.Bind(new IPEndPoint(IPAddress.Any, portToBind));
            Console.Write("Endpoint of your peer: ");

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

            Console.WriteLine(String.Format("Connecting to at {0}:{1}...", introducerEndpoint.Address, introducerEndpoint.Port));
            Outgoing.Connect(introducerEndpoint.Address, introducerEndpoint.Port);

            Console.ReadLine();

            Application.Run();
        }