コード例 #1
0
ファイル: Delay.cs プロジェクト: peteshand/cs-essential
 static void init()
 {
     if (initialized)
     {
         return;
     }
     initialized  = true;
     delayObjects = new List <IDelayObject>();
     EnterFrame.Add(OnTick);
 }
コード例 #2
0
        public void Init(dynamic settings = null) // IPAddress multicastIPaddress, int port, IPAddress localIPaddress = null
        {
            //if (settings == null){
            port = 33333;
            multicastIPaddress = IPAddress.Parse("233.255.255.255");
            if (settings != null)
            {
                int    _port          = (int)settings.GetType().GetProperty("port").GetValue(settings, null);
                string _multicastAddr = (string)settings.GetType().GetProperty("multicastAddr").GetValue(settings, null);
                if (_multicastAddr != null)
                {
                    multicastIPaddress = IPAddress.Parse(_multicastAddr);
                }
            }

            // Create endpoints
            //IPAddress address = IPAddress.Parse("233.255.255.255");
            //int port = 0;
            remoteEndPoint = new IPEndPoint(multicastIPaddress, port);
            localEndPoint  = new IPEndPoint(localIPaddress, port);

            // Create and configure UdpClient
            udpclient = new UdpClient();
            // The following three lines allow multiple clients on the same PC
            udpclient.ExclusiveAddressUse = false;
            udpclient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            udpclient.ExclusiveAddressUse = false;
            // Bind, Join
            udpclient.Client.Bind(localEndPoint);
            udpclient.JoinMulticastGroup(multicastIPaddress, localIPaddress);

            // Start listening for incoming data
            //udpclient.BeginReceive(new AsyncCallback(ReceivedCallback), null);

            EnterFrame.Add(Tick);
        }