예제 #1
0
        /// <summary>
        /// Receives and unpacks an OSC packet.
        /// A <see cref="OSCPacket"/>
        /// </summary>
        private void Receive()
        {
            IPEndPoint ip = null;

            try
            {
                byte[] bytes = _udpClient.Receive(ref ip);

                if (bytes != null && bytes.Length > 0)
                {
                    OSCPacket packet = OSCPacket.Unpack(bytes);

                    _lastReceivedPacket = packet;

                    PacketReceivedEvent(this, _lastReceivedPacket);
                }
            }
            catch {
                throw new Exception(String.Format("Can't create server at port {0}", _localPort));
            }
        }
예제 #2
0
        private async void Socket_MessageReceived(Windows.Networking.Sockets.DatagramSocket sender,
                                                  Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs args)
        {
            // lock multi event
            socket.MessageReceived -= Socket_MessageReceived;

            //Debug.Log("OSCSERVER UWP  Socket_MessageReceived");

            //Read the message that was received from the UDP echo client.
            //Stream streamIn = args.GetDataStream().AsStreamForRead();
            DataReader reader = args.GetDataReader();

            //StreamReader reader = new StreamReader(streamIn);
            try
            {
                uint   stringLength = reader.UnconsumedBufferLength;
                byte[] bytes        = new byte[stringLength];
                reader.ReadBytes(bytes);

                //string message = await reader.ReadToEndAsync()
                //                 .ConfigureAwait(continueOnCapturedContext: false);
                //byte[] bytes = System.Text.Encoding.UTF8.GetBytes(message);

                OSCPacket packet = OSCPacket.Unpack(bytes);
                _lastReceivedPacket = packet;

                PacketReceivedEvent(this, _lastReceivedPacket);
            }
            catch (System.Exception e)
            {
                WorldErrors.Print(e.Message);
            }
            finally
            {
                //streamIn.Dispose();
                reader.Dispose();
                // unlock multi event
                socket.MessageReceived += Socket_MessageReceived;
            }
        }
예제 #3
0
파일: OSCServer.cs 프로젝트: thmslhst/Toro
        /// <summary>
        /// Receives and unpacks an OSC packet.
        /// A <see cref="OSCPacket"/>
        /// </summary>
        private void Receive()
        {
            IPEndPoint ip = null;

            try
            {
                byte[] bytes = _udpClient.Receive(ref ip);

                if (bytes != null && bytes.Length > 0)
                {
                    OSCPacket packet = OSCPacket.Unpack(bytes);

                    _lastReceivedPacket = packet;

                    PacketReceivedEvent(this, _lastReceivedPacket);
                }
            }
            catch {
                // Lance une exception à chaque fois qu'on exit le player... bizarre...
                //throw new Exception(String.Format("Can't create server at port {0}", _localPort));
            }
        }
예제 #4
0
        /// <summary>
        /// Receives and unpacks an OSC packet.
        /// A <see cref="OSCPacket"/>
        /// </summary>
        private void Receive()
        {
            IPEndPoint ip = null;

            try
            {
                byte[] bytes = _udpClient.Receive(ref ip);

                if (bytes != null && bytes.Length > 0)
                {
                    OSCPacket packet = OSCPacket.Unpack(bytes);
                    lock (_lastReceivedPacket);
                    _lastReceivedPacket.Add(packet);
                    if (_lastReceivedPacket.Count > MaxPacketQueue)
                    {
                        _lastReceivedPacket.RemoveAt(0);
                    }
                    recievedFlag = true;
                }
            }
            catch {
                throw new Exception(String.Format("Can't create server at port {0}", _localPort));
            }
        }