Beispiel #1
0
        void ReceiveCallback(IAsyncResult result)
        {
            Monitor.Enter(callbackLock);
            Byte[] bytes = null;

            IPEndPoint remoteEP = null;

            try
            {
                bytes = receivingUdpClient.EndReceive(result, ref remoteEP);
            }
            catch (ObjectDisposedException e)
            {
                // Ignore if disposed. This happens when closing the listener
            }

            // Process bytes
            if (bytes != null && bytes.Length > 0)
            {
                if (BytePacketCallback != null)
                {
                    BytePacketCallback(bytes);
                }
                else if (OscPacketCallback != null)
                {
                    OscPacket packet = null;
                    try
                    {
                        packet = OscPacket.GetPacket(bytes, remoteEP);
                    }
                    catch (Exception e)
                    {
                        // If there is an error reading the packet, null is sent to the callback
                    }

                    OscPacketCallback(packet);
                }
                else
                {
                    lock (queue)
                    {
                        queue.Enqueue(bytes);
                    }
                }
            }

            if (closing)
            {
                ClosingEvent.Set();
            }
            else
            {
                // Setup next async event
                AsyncCallback callBack = new AsyncCallback(ReceiveCallback);
                receivingUdpClient.BeginReceive(callBack, remoteEP);
            }
            Monitor.Exit(callbackLock);
        }
Beispiel #2
0
        void ReceiveCallback(IAsyncResult result)
        {
            Monitor.Enter(callbackLock);
            Byte[] bytes = null;

            try
            {
                bytes = receivingUdpClient.EndReceive(result, ref RemoteIpEndPoint);
            }
            finally {
            }

            // Process bytes
            if (bytes != null && bytes.Length > 0)
            {
                if (BytePacketCallback != null)
                {
                    BytePacketCallback(bytes);
                }
                else if (OscPacketCallback != null)
                {
                    OscPacket packet = null;
                    try
                    {
                        packet = OscPacket.GetPacket(bytes);
                    }
                    finally {
                    }

                    OscPacketCallback(packet);
                }
                else
                {
                    lock (queue)
                    {
                        queue.Enqueue(bytes);
                    }
                }
            }

            if (closing)
            {
                ClosingEvent.Set();
            }
            else
            {
                // Setup next async event
                AsyncCallback callBack = new AsyncCallback(ReceiveCallback);
                receivingUdpClient.BeginReceive(callBack, null);
            }
            Monitor.Exit(callbackLock);
        }
Beispiel #3
0
        public OscPacket Receive()
        {
            if (closing)
            {
                throw new Exception("UDPListener has been closed.");
            }

            lock (queue)
            {
                if (queue.Count() > 0)
                {
                    byte[] bytes  = queue.Dequeue();
                    var    packet = OscPacket.GetPacket(bytes);
                    return(packet);
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #4
0
 public void Send(OscPacket packet)
 {
     byte[] data = packet.GetBytes();
     Send(data);
 }
Beispiel #5
0
 public void Send(OscPacket packet)
 {
     byte[] data = packet.GetBytes();
     Send(data);
 }