コード例 #1
0
        public void ConnectAsyncIPV6CallbackTest()
        {
            ManualResetEventSlim mevent = new ManualResetEventSlim(false);

            mevent.Reset();
            try
            {
                ipv6Protocol.Listen();
                UdpProtocol ipvClient = this.CreateIPV6ClientProtocol(ipv6ServerAddress);
                ISocket     udpSocket = null;
                ipvClient.ConnectAsync((socket) =>
                {
                    udpSocket = socket;
                    mevent.Set();
                }, ipv6ServerAddress, PORT);
                Assert.IsTrue(mevent.Wait(10000), "Connection never triggered callback.");
                sockets.Add(udpSocket);
                Assert.IsNotNull(udpSocket, "Callback did not receive a socket.");
                Assert.IsTrue(udpSocket.Connected, "A connection could not be established.");
                udpSocket.Disconnect();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
コード例 #2
0
        private static ManualRekeyApplication GetMra(BaseDevice device)
        {
            if (device.DliIpDevice.Protocol == DliIpDevice.ProtocolOptions.UDP)
            {
                int timeout = 5000;

                UdpProtocol udpProtocol = new UdpProtocol(device.DliIpDevice.Hostname, device.DliIpDevice.Port, timeout);

                bool motVariant;

                if (device.DliIpDevice.Variant == DliIpDevice.VariantOptions.Standard)
                {
                    motVariant = false;
                }
                else if (device.DliIpDevice.Variant == DliIpDevice.VariantOptions.Motorola)
                {
                    motVariant = true;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Variant");
                }

                return(new ManualRekeyApplication(udpProtocol, motVariant));
            }
            else
            {
                throw new ArgumentOutOfRangeException("Protocol");
            }
        }
コード例 #3
0
        public void Initialize()
        {
            ManualResetEventSlim mevent = new ManualResetEventSlim(false);

            ipv4Server         = new UdpProtocol();
            ipv4Server.Address = serverAddress;
            ipv4Server.Port    = PORT;
            mevent.Reset();
            ipv4Server.OnConnectionRequested += (socket) =>
            {
                ipv4ServerClient = socket;
                mevent.Set();
            };
            ipv4Server.Listen();
            ipv6Server         = new UdpProtocol();
            ipv6Server.Address = IPAddress.IPv6Any.ToString();
            ipv6Server.Port    = PORT;
            ipv6Server.Listen();
            ipv6Server.OnConnectionRequested += (socket) =>
            {
                ipv6ServerClient = socket;
                mevent.Set();
            };
            ipv4Client = this.CreateIPV4ClientProtocol(clientAddress).Connect(serverAddress, PORT);
            mevent.Wait(1000);
            mevent.Reset();
            ipv6Client = this.CreateIPV6ClientProtocol(null).Connect(ipv6ServerAddress, PORT);
            mevent.Wait(1000);
        }
コード例 #4
0
        protected AbstractHybridSession(UdpProtocol udp)
        {
            Udp       = udp;
            Udp.Data += HandleUdpData;

            Info = new ProtocolInfo(60);
        }
コード例 #5
0
 public void Initialize()
 {
     ipv4Protocol         = new UdpProtocol();
     ipv4Protocol.Address = serverAddress;
     ipv4Protocol.Port    = PORT;
     ipv6Protocol         = new UdpProtocol();
     ipv6Protocol.Port    = PORT;
     ipv6Protocol.Address = ipv6ServerAddress;
 }
コード例 #6
0
        protected void AddRemotePlayer(string ip, int port, int queue)
        {
            isSynchronizing = true;

            endpoints[queue] = new UdpProtocol(udp, poll, queue, ip, port, localConnectStatus, logger);
            endpoints[queue].DisconnectTimeout     = disconnectTimeout;
            endpoints[queue].DisconnectNotifyStart = disconnectNotifyStart;
            endpoints[queue].Synchronize();
        }
コード例 #7
0
        public void DisposeTest()
        {
            var ipv4Protocol = new UdpProtocol();

            ipv4Protocol.Port = PORT;
            ipv4Protocol.Listen();
            ipv4Protocol.Dispose();
            Assert.IsFalse(ipv4Protocol.Listening, "The protocol Listening property was true after disposing the protocol.");
        }
コード例 #8
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (Udp != null)
                {
                    Udp.Dispose();
                    Udp = null;
                }

                Players = null;
            }

            GC.SuppressFinalize(this);
        }
コード例 #9
0
 public void ConnectIPV6Test()
 {
     try
     {
         ipv6Protocol.Listen();
         UdpProtocol ipvClient = this.CreateIPV6ClientProtocol(ipv6ServerAddress);
         var         udpSocket = ipvClient.Connect(ipv6ServerAddress, PORT);
         sockets.Add(udpSocket);
         Assert.IsNotNull(udpSocket);
         Assert.IsTrue(udpSocket.Connected, "A connection could not be established.");
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.ToString());
     }
 }
コード例 #10
0
        public async Task ConnectAsyncIPV6TaskTest()
        {
            try
            {
                ipv6Protocol.Listen();
                UdpProtocol ipvClient = this.CreateIPV6ClientProtocol(ipv6ServerAddress);
                var         udpSocket = await ipvClient.ConnectAsync(ipv6ServerAddress, PORT);

                sockets.Add(udpSocket);
                Assert.IsNotNull(udpSocket, "The udpSocket instance was null.");
                Assert.IsTrue(udpSocket.Connected, "A connection could not be established.");
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
コード例 #11
0
        protected GGPOErrorCode AddSpectator(string ip, int port)
        {
            if (numSpectators == Constants.MaxSpectators)
            {
                return(GGPOErrorCode.TooManySpectators);
            }

            // Currently, we can only add spectators before the game starts.
            if (isSynchronizing)
            {
                return(GGPOErrorCode.InvalidRequest);
            }
            int queue = numSpectators++;

            spectators[queue] = new UdpProtocol(udp, poll, queue + 1000, ip, port, localConnectStatus, logger);
            spectators[queue].DisconnectTimeout     = disconnectTimeout;
            spectators[queue].DisconnectNotifyStart = disconnectNotifyStart;
            spectators[queue].Synchronize();

            return(GGPOErrorCode.OK);
        }
コード例 #12
0
        public SpectatorBackend(IGGPOSessionCallbacks callbacks,
                                ILog logger,
                                int localPort,
                                int numPlayers,
                                int inputSize,
                                string hostIp,
                                int hostPort)
        {
            this.callbacks  = callbacks;
            this.logger     = logger;
            this.numPlayers = numPlayers;
            this.inputSize  = inputSize;

            // Initialize the UDP port
            var udpEndpoint = new IPEndPoint(IPAddress.Any, localPort);

            udp = new Udp(localPort, poll, this);

            // Initialize the host endpoint
            host = new UdpProtocol(udp, poll, 0, hostIp, hostPort, null, logger);
        }
コード例 #13
0
        public PeerToPeerBackend(IGGPOSessionCallbacks callbacks, ILog logger, int localPort, int numPlayers, int inputSize)
        {
            this.numPlayers = numPlayers;
            this.inputSize  = inputSize;
            this.callbacks  = callbacks;
            this.logger     = logger;

            for (int i = 0; i < Constants.MaxPlayers; i++)
            {
                localConnectStatus[i] = new NetworkConnectStatus();
            }

            for (int i = 0; i < Constants.MaxSpectators; i++)
            {
                spectators[i] = new UdpProtocol(logger);
            }

            isSynchronizing = true;
            endpoints       = new UdpProtocol[numPlayers];
            for (int i = 0; i < numPlayers; i++)
            {
                endpoints[i] = new UdpProtocol(logger);
            }

            // Initialize the synchronziation layer
            sync = new Sync(localConnectStatus,
                            new Sync.Config
            {
                numPlayers          = numPlayers,
                inputSize           = inputSize,
                callbacks           = callbacks,
                numPredictionFrames = Constants.MaxPredictionFrames,
            });

            // Initialize the UDP port
            var udpEndpoint = new IPEndPoint(IPAddress.Any, localPort);

            udp = new Udp(localPort, poll, this);
        }
コード例 #14
0
        public void OnConnectionRequestedTest()
        {
            ipv4Protocol.Listen();
            ManualResetEventSlim mevent = new ManualResetEventSlim(false);

            mevent.Reset();
            bool eventInvoked = false;

            ipv4Protocol.OnConnectionRequested += (socket) =>
            {
                eventInvoked = true;
                mevent.Set();
            };
            UdpProtocol ipvClient    = this.CreateIPV4ClientProtocol(clientAddress);
            ISocket     clientSocket = ipvClient.Connect(serverAddress, PORT);

            sockets.Add(clientSocket);

            clientSocket.Send(TestData.GetDummyStream().ToArray());
            mevent.Wait(1000);
            Assert.IsTrue(clientSocket.Connected, "A socket connection was not established.");
            Assert.IsTrue(eventInvoked, "On Connection Requested event was not invoked");
        }
コード例 #15
0
 public DataLinkIndependentProtocol(UdpProtocol udpProtocol, bool motVariant)
 {
     Protocol   = udpProtocol;
     MotVariant = motVariant;
 }
コード例 #16
0
 public ManualRekeyApplication(UdpProtocol udpProtocol, bool motVariant)
 {
     DeviceProtocol = new DataLinkIndependentProtocol(udpProtocol, motVariant);
     WithPreamble   = true;
     Mfid           = motVariant ? (byte)0x90 : (byte)0x00;
 }
コード例 #17
0
 public MessagesHandler(int port)
 {
     udp = new UdpProtocol(port);
 }
コード例 #18
0
 public DataHandler(int port)
 {
     localPort = port;
     client    = new UdpProtocol(localPort);
 }