Exemple #1
0
 public void Start(int proxyCount = 1)
 {
     for (int i = 0; i < proxyCount; i++)
     {
         RaknetUdpProxy raknetUdpProxy = new RaknetUdpProxy();
         var            proxyStarted   = raknetUdpProxy.Start();
         if (proxyStarted)
         {
             var theProxyAddress = raknetUdpProxy.GetMyIpAddress();
             if (!proxyDcit.Any(kvPair => kvPair.Key.Address == theProxyAddress.Address && kvPair.Key.Port == theProxyAddress.Port))
             {
                 proxyDcit.Add(theProxyAddress, raknetUdpProxy);
             }
         }
     }
 }
Exemple #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;
        }