static void ListenLoop()
        {
            try
            {
                while (m_Receiver.State != OscSocketState.Closed)
                {
                    // if we are in a state to recieve
                    if (m_Receiver.State == OscSocketState.Connected)
                    {
                        // get the next message
                        // this will block until one arrives or the socket is closed
                        OscPacket packet = m_Receiver.Receive();

                        switch (m_Listener.ShouldInvoke(packet))
                        {
                        case OscPacketInvokeAction.Invoke:
                            Console.WriteLine("Received packet");
                            m_Listener.Invoke(packet);
                            break;

                        case OscPacketInvokeAction.DontInvoke:
                            Console.WriteLine("Cannot invoke");
                            Console.WriteLine(packet.ToString());
                            break;

                        case OscPacketInvokeAction.HasError:
                            Console.WriteLine("Error reading osc packet, " + packet.Error);
                            Console.WriteLine(packet.ErrorMessage);
                            break;

                        case OscPacketInvokeAction.Pospone:
                            Console.WriteLine("Posponed bundle");
                            Console.WriteLine(packet.ToString());
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // if the socket was connected when this happens
                // then tell the user
                if (m_Receiver.State == OscSocketState.Connected)
                {
                    Console.WriteLine("Exception in listen loop");
                    Console.WriteLine(ex.Message);
                }
            }
        }
    // Update is called once per frame
    void Update()
    {
        int i = 0;

        // if we are in a state to recieve
        while (i++ < MaxMessagesToProcessPerFrame &&
               m_Receiver.State == OscSocketState.Connected)
        {
            OscPacket packet;

            // get the next message this will not block
            if (m_Receiver.TryReceive(out packet) == false)
            {
                return;
            }

            switch (m_Manager.ShouldInvoke(packet))
            {
            case OscPacketInvokeAction.Invoke:
                // Debug.Log ("Received packet");
                m_Manager.Invoke(packet);
                break;

            case OscPacketInvokeAction.DontInvoke:
                Debug.LogWarning("Cannot invoke");
                Debug.LogWarning(packet.ToString());
                break;

            case OscPacketInvokeAction.HasError:
                Debug.LogError("Error reading osc packet, " + packet.Error);
                Debug.LogError(packet.ErrorMessage);
                break;

            case OscPacketInvokeAction.Pospone:
                Debug.Log("Posponed bundle");
                Debug.Log(packet.ToString());
                break;

            default:
                break;
            }
        }
    }
Exemplo n.º 3
0
        internal void PacketReceived(OscPacket packet)
        {
            if (packet.Error != OscPacketError.None)
            {
                OnError(Strings.Connection_ReceivedCorruptedPacket, packet.ErrorMessage);
            }
            else
            {
                OnReceivePacket(packet);

                try
                {
                    oscAddressManager.Invoke(packet);
                }
                catch (Exception ex)
                {
                    OnException(Strings.Connection_ErrorWhileProcessingPacket, ex);
                }
            }
        }
Exemplo n.º 4
0
        static void ListenLoop()
        {
            try
            {
                while (m_Receiver.State != OscSocketState.Closed)
                {
                    // if we are in a state to recieve
                    if (m_Receiver.State == OscSocketState.Connected)
                    {
                        // get the next message
                        // this will block until one arrives or the socket is closed
                        OscPacket packet = m_Receiver.Receive();

                        if (packet == null)
                        {
                            continue;
                        }

                        if (packet.Error == OscPacketError.None)
                        {
                            m_Listener.Invoke(packet);
                        }
                        else
                        {
                            Console.WriteLine("Error reading osc packet, " + packet.Error);
                            Console.WriteLine(packet.ErrorMessage);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // if the socket was connected when this happens
                // then tell the user
                if (m_Receiver.State == OscSocketState.Connected)
                {
                    Console.WriteLine("Exception in listen loop");
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 5
0
        private void ListenLoop()
        {
            try
            {
                while (OscReceiver.State != OscSocketState.Closed)
                {
                    if (OscReceiver.State != OscSocketState.Connected)
                    {
                        continue;
                    }

                    OscPacket packet = this.OscReceiver.Receive();

                    BeginSessionContext?.Invoke(packet.Origin);

                    if (ShouldProcessPackage(packet) == false)
                    {
                        continue;
                    }

                    if (packet.Error == OscPacketError.None)
                    {
                        PacketReceived?.Invoke(packet);
                        OscAddressManager.Invoke(packet);
                    }

                    EndSessionContext?.Invoke(packet.Origin);
                }
            }
            catch (Exception ex)
            {
                if (ex is OscSocketStateException && OscReceiver.State != OscSocketState.Connected)
                {
                    return;
                }

                InnerExceptionThrown?.Invoke(new InnerThreadException("Exception in listen loop", ex));
            }
        }
        private void Send_Click(object sender, EventArgs e)
        {
            try
            {
                // parse the message
                OscPacket packet = OscPacket.Parse(m_MessageBox.Text);

                switch (m_Manager.ShouldInvoke(packet))
                {
                case OscPacketInvokeAction.Invoke:
                    m_Manager.Invoke(packet);
                    break;

                case OscPacketInvokeAction.DontInvoke:
                    Debug.WriteLine("Cannot invoke");
                    Debug.WriteLine(packet.ToString());
                    break;

                case OscPacketInvokeAction.HasError:
                    Debug.WriteLine("Error reading osc packet, " + packet.Error);
                    Debug.WriteLine(packet.ErrorMessage);
                    break;

                case OscPacketInvokeAction.Pospone:
                    Debug.WriteLine("Posponed bundle");
                    Debug.WriteLine(packet.ToString());
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                // explicitly tell the user why the message failed to parse
                MessageBox.Show(ex.Message, "Error parsing message");
            }
        }
Exemplo n.º 7
0
        private void Send_Click(object sender, EventArgs e)
        {
            try
            {
                // parse the message
                OscPacket packet = OscPacket.Parse(m_MessageBox.Text);

                if (packet.Error != OscPacketError.None)
                {
                    Debug.WriteLine("Error reading osc packet, " + packet.Error);
                    Debug.WriteLine(packet.ErrorMessage);

                    return;
                }

                m_Manager.Invoke(packet);
            }
            catch (Exception ex)
            {
                // explicitly tell the user why the message failed to parse
                MessageBox.Show(ex.Message, "Error parsing message");
            }
        }
Exemplo n.º 8
0
        public void InvokeTest1_Bad()
        {
            try
            {
                using (OscAddressManager target = new OscAddressManager())
                {
                    string          address = "/test";
                    OscMessageEvent @event  = new OscMessageEvent((OscMessage msg) => { Debug.WriteLine(msg.ToString()); });
                    target.Attach(address, @event);

                    OscBundle bundle   = new OscBundle(DateTime.Now, new OscMessage("/foo"));
                    bool      expected = false;
                    bool      actual;

                    actual = target.Invoke(bundle);

                    Assert.AreEqual(expected, actual);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Exemplo n.º 9
0
        public void InvokeTest_Good()
        {
            try
            {
                using (OscAddressManager target = new OscAddressManager())
                {
                    string          address = "/test";
                    OscMessageEvent @event  = new OscMessageEvent((OscMessage msg) => { Debug.WriteLine(msg.ToString()); });
                    target.Attach(address, @event);

                    OscMessage message  = new OscMessage("/test");
                    bool       expected = true;
                    bool       actual;

                    actual = target.Invoke(message);

                    Assert.AreEqual(expected, actual);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public void Load(string filePath, IReporter reporter = null)
        {
            lock (readWriteLock)
            {
                using (OscFileReader fileReader = new OscFileReader(Helper.ResolvePath(filePath), OscPacketFormat.String))
                    using (OscAddressManager manager = new OscAddressManager())
                    {
                        foreach (ISettingValue value in AllValues)
                        {
                            if (value.IsReadOnly == true)
                            {
                                continue;
                            }

                            manager.Attach(value.OscAddress, value.OnLocalMessage);
                        }

                        fileReader.PacketRecived += delegate(OscPacket packet)
                        {
                            if (packet.Error != OscPacketError.None)
                            {
                                if (reporter != null)
                                {
                                    reporter.OnError(this, new MessageEventArgs(packet.ErrorMessage));
                                }

                                return;
                            }

                            manager.Invoke(packet);
                        };

                        fileReader.ReadToEnd();
                    }
            }
        }