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; } } }
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"); } }