Example #1
0
        public void Do()
        {
            Console.WriteLine("请输入NatServer IPAddress:");
            string natServerIpAddress = Console.ReadLine();

            Console.WriteLine("请输入NatServer Port:");
            string natServerPort = Console.ReadLine();

            ushort natServerPortUshort = 0;

            ushort.TryParse(natServerPort, out natServerPortUshort);

            Console.WriteLine("请输入Proxy IPAddress:");
            string proxyIpAddress = Console.ReadLine();

            Console.WriteLine("请输入Proxy Port:");
            string proxyPort = Console.ReadLine();

            ushort proxyPortUshort = 0;

            ushort.TryParse(proxyPort, out proxyPortUshort);

            var raknetUdpNATPTServerAddress = new RaknetIPAddress(natServerIpAddress, natServerPortUshort);
            var raknetUdpProxyAddress       = new RaknetIPAddress(proxyIpAddress, proxyPortUshort);

            //start PeerServer
            RaknetUdpPeerServer raknetUdpPeerServer = new RaknetUdpPeerServer();
            var udpPeerServerStarted = raknetUdpPeerServer.Start().Connect(raknetUdpNATPTServerAddress, raknetUdpProxyAddress);

            if (!udpPeerServerStarted)
            {
                Console.WriteLine("UdpPeerServer启动失败");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("UdpPeerServer启动成功,IP地址为:{0},GUID:{1}",
                              raknetUdpPeerServer.GetMyIpAddress().ToString(),
                              raknetUdpPeerServer.GetMyGuid()
                              );
            raknetUdpPeerServer.OnConnect       += RaknetUdpPeerServer_OnConnect;
            raknetUdpPeerServer.OnConnectFailed += RaknetUdpPeerServer_OnConnectFailed;
            raknetUdpPeerServer.OnReceive       += RaknetUdpPeerServer_OnReceive;

            ConsoleCloseHandler.raknetUdpPeerServer = raknetUdpPeerServer;
            ConsoleCloseHandler.SetConsoleCtrlHandler(ConsoleCloseHandler.cancelHandler, true);

            Console.WriteLine("------------------外网地址:{0}", IPAddressUtils.GetOuterNatIP());

            Console.WriteLine("PeerServer GUID:{0}", raknetUdpPeerServer.GetMyGuid());
        }
Example #2
0
        public void Do()
        {
            //#region udpProxy

            //start proxy
            RaknetUdpProxy raknetUdpProxy = new RaknetUdpProxy();
            var            proxyStarted   = raknetUdpProxy.Start(RaknetConfig.proxyAddress);

            if (!proxyStarted)
            {
                Console.WriteLine("Proxy启动失败");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("Proxy启动成功,IP地址为:{0}", raknetUdpProxy.GetMyIpAddress().ToString());

            //#endregion


            ////start natServer
            //RaknetUdpNATPTServer raknetUdpNATPTServer = new RaknetUdpNATPTServer();
            //var udpNATPTServerStarted = raknetUdpNATPTServer.Start(RaknetConfig.natServerAddress);
            //if (!udpNATPTServerStarted)
            //{
            //	Console.WriteLine("UdpNATPTServer启动失败");
            //	Console.ReadKey();
            //	return;
            //}
            //Console.WriteLine("UdpNATPTServer启动成功,IP地址为:{0}", raknetUdpNATPTServer.GetMyIpAddress().ToString());

            //var raknetUdpNATPTServerAddress = raknetUdpNATPTServer.GetMyIpAddress();
            var raknetUdpProxyAddress = raknetUdpProxy.GetMyIpAddress();

            var raknetUdpNATPTServerAddress = new RaknetIPAddress("47.94.21.115", 666);
            //var raknetUdpProxyAddress = new RaknetIPAddress("47.94.21.115", 777);

            //start PeerServer
            RaknetUdpPeerServer raknetUdpPeerServer = new RaknetUdpPeerServer();
            var udpPeerServerStarted = raknetUdpPeerServer.Start().Connect(raknetUdpNATPTServerAddress, raknetUdpProxyAddress);

            if (!udpPeerServerStarted)
            {
                Console.WriteLine("UdpPeerServer启动失败");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("UdpPeerServer启动成功,IP地址为:{0},GUID:{1}",
                              raknetUdpPeerServer.GetMyIpAddress().ToString(),
                              raknetUdpPeerServer.GetMyGuid()
                              );
            raknetUdpPeerServer.OnConnect       += RaknetUdpPeerServer_OnConnect;
            raknetUdpPeerServer.OnConnectFailed += RaknetUdpPeerServer_OnConnectFailed;
            raknetUdpPeerServer.OnReceive       += RaknetUdpPeerServer_OnReceive;

            //start PeerClient
            RaknetUdpPeerClient raknetUdpPeerClient = new RaknetUdpPeerClient();
            var udpPeerClientStarted = raknetUdpPeerClient.Start().Connect(raknetUdpNATPTServerAddress, raknetUdpProxyAddress, raknetUdpPeerServer.GetMyIpAddress(), raknetUdpPeerServer.GetMyGuid());

            if (!udpPeerClientStarted)
            {
                Console.WriteLine("UdpPeerClient启动失败");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("UdpPeerClient启动成功,IP地址为:{0}", raknetUdpPeerClient.GetMyIpAddress().ToString());
            raknetUdpPeerClient.OnConnect       += RaknetUdpPeerClient_OnConnect;
            raknetUdpPeerClient.OnConnectFailed += RaknetUdpPeerClient_OnConnectFailed;
            raknetUdpPeerClient.OnReceive       += RaknetUdpPeerClient_OnReceive;
        }