UDPPacketIO.ReceivePacket C# (CSharp) Method

ReceivePacket() public method

Receive a packet of bytes over UDP.
public ReceivePacket ( byte buffer ) : int
buffer byte The buffer to be read into.
return int
    public int ReceivePacket(byte[] buffer)
    {
        if (!IsOpen())
            Open();
        if (!IsOpen())
            return 0;

      IPEndPoint iep = new IPEndPoint(IPAddress.Any, localPort);
      byte[] incoming = Receiver.Receive( ref iep );
      int count = Math.Min(buffer.Length, incoming.Length);
      System.Array.Copy(incoming, buffer, count);
      return count;
    }

Usage Example

Exemplo n.º 1
0
    /// <summary>
    /// Read Thread.  Loops waiting for packets.  When a packet is received, it is
    /// dispatched to any waiting All Message Handler.  Also, the address is looked up and
    /// any matching handler is called.
    /// </summary>
    private void Read()
    {
        try
        {
            while (ReaderRunning)
            {
                int length = OscPacketIO.ReceivePacket(buffer);

                if (length > 0)
                {
                    lock (ReadThreadLock)
                    {
                        if (paused == false)
                        {
                            ArrayList newMessages = OSC.PacketToOscMessages(buffer, length);
                            messagesReceived.AddRange(newMessages);
                        }
                    }
                }
                else
                {
                    Thread.Sleep(5);
                }
            }
        }

        catch (Exception e)
        {
            Debug.Log("ThreadAbortException" + e);
        }
        finally
        {
        }
    }
All Usage Examples Of UDPPacketIO::ReceivePacket