Пример #1
0
        public bool Start()
        {
            try
            {
                ServerSocket.Connect(IPAddress.Parse("127.0.0.1"), SERVICE_PORT);
                ReadFeatures();
            }
            catch (Exception e)
            {
                Log.D($"Failed to Read Features, {e.Message}");
                Log.D($"\tPairingSupported={PairingSupported}, SoundMonitorSupported={SoundMonitorSupported}");
                FeatureStateChanged?.Invoke(this, Features);
                return(false);
            }

            return(true);
        }
Пример #2
0
        private void ReadFeatures()
        {
            State         BufferState = new State();
            AsyncCallback InteralSockCallback;
            EndPoint      epFrom = new IPEndPoint(IPAddress.Any, 0);

            Features = 0x0;
            Send("features");

            ServerSocket.BeginReceiveFrom(BufferState.buffer, 0, BUF_SIZE, SocketFlags.None, ref epFrom, InteralSockCallback = (ar) =>
            {
                State so = (State)ar.AsyncState;

                int bytes = 0;
                try
                {
                    bytes = ServerSocket.EndReceiveFrom(ar, ref epFrom);
                }
                catch (SocketException ex)
                {
                    bytes = 0;
                    Log.D($"ReadFeatures: Message={ex.Message}, SocketErrorCode={ex.SocketErrorCode}");
                }

                if (bytes > 0)
                {
                    Features = BitConverter.ToUInt32(so.buffer, 0);
                    Log.D($"ReadFeatures: RECV: {epFrom}, {bytes}, {Features}");
                }

                if (Features > 0)
                {
                    Log.D($"ReadFeatures: String Message Loop, PairingSupported={PairingSupported}, SoundMonitorSupported={SoundMonitorSupported}");
                    ReceiveInLoop();
                }
                else
                {
                    Log.D($"ReadFeatures: No Features Supported");
                }

                FeatureStateChanged?.Invoke(this, Features);
            }, BufferState);
        }