Example #1
0
        /// <summary>
        /// Unpacks an OSC bundle from a data stream.
        /// </summary>
        /// <param name="data">
        /// A <see cref="System.Byte[]"/>
        /// </param>
        /// <param name="start">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <param name="end">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <returns>
        /// A <see cref="OSCBundle"/>
        /// </returns>
        public new static OSCBundle Unpack(byte[] data, ref int start, int end)
        {
            string address = OSCPacket.UnpackValue <string>(data, ref start);

            Trace.Assert(address == BUNDLE);

            long      timeStamp = OSCPacket.UnpackValue <long>(data, ref start);
            OSCBundle bundle    = new OSCBundle(timeStamp);

            while (start < end)
            {
                int length    = OSCPacket.UnpackValue <int>(data, ref start);
                int packetEnd = start + length;
                bundle.Append(OSCPacket.Unpack(data, ref start, packetEnd));
            }

            return(bundle);
        }
Example #2
0
        public void SendTo(OSCPacket packet, string host, int port)
        {
            byte[] data = packet.BinaryData;
            try
            {
                //Debug.Log("SendTo :"+host+"/"+port);
                _ipAddress = IPAddress.Parse(host);
                _port      = port;

                //Connect ();
                var tmpUdpClient = new UdpClient(); //BOF BOF
                tmpUdpClient.Send(data, data.Length, host, port);
                //Debug.Log ("Sent");
            }
            catch (Exception e)
            {
                throw new Exception(String.Format("Can't send OSC packet to client {0} : {1} | {2}", _ipAddress, _port, e.ToString()));
            }
        }
Example #3
0
        void didReceivedEvent(OSCServer sender, OSCPacket packet)
        {
            lock (_queue)
            {
                if (packet.IsBundle())
                {
                    var bundle = packet as OSCBundle;

                    foreach (object obj in bundle.Data)
                    {
                        OSCMessage msg = obj as OSCMessage;

                        if (OSCMaster.Instance.LogIncoming)
                        {
                            Debug.Log("[" + Name + "] " + msg.Address);
                            foreach (var data in msg.Data)
                            {
                                Debug.Log(data);
                            }
                        }

                        _queue.Enqueue(msg);
                    }
                }
                else
                {
                    OSCMessage msg = packet as OSCMessage;

                    if (OSCMaster.Instance.LogIncoming)
                    {
                        Debug.Log("[" + Name + "] " + msg.Address);
                        foreach (var data in msg.Data)
                        {
                            Debug.Log(data);
                        }
                    }

                    _queue.Enqueue(msg);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Packs the OSC message to binary data.
        /// </summary>
        override public void Pack()
        {
            List <byte> data = new List <byte>();

            data.AddRange(OSCPacket.PackValue(_address));
            OSCPacket.PadNull(data);

            data.AddRange(OSCPacket.PackValue(_typeTag));
            OSCPacket.PadNull(data);

            foreach (object value in _data)
            {
                data.AddRange(OSCPacket.PackValue(value));
                if (value is string || value is byte[])
                {
                    OSCPacket.PadNull(data);
                }
            }

            this._binaryData = data.ToArray();
        }