Пример #1
0
        /// <summary>
        /// Constructor.
        /// Initialise and setup the socket server.
        /// </summary>
        public SocketServer(UInt16 port)
        {
            this.communication = new Communication();
            this.welcomeMessage = new MessageWelcome();
            welcomeMessage.AuthMethod = AllowedAuth;
            this.statusMessage = new MessageStatus();
            this.volumeMessage = new MessageVolume();
            this.nowPlayingMessage = new MessageNowPlaying();
            this.nowPlayingMessageUpdate = new MessageNowPlayingUpdate();
            this.nowPlayingPropertiesUpdate = new MessagePropertyChanged();
            this.currentFacadeInfoMessage = new MessageFacadeInfo();

            this.port = port;

            initSocket();
        }
Пример #2
0
        /// <summary>
        /// Sends the property to all clients who have registered for it
        /// </summary>
        /// <param name="tag">name of the property</param>
        /// <param name="tagValue">value of the property</param>
        public void SendPropertyToClient(string tag, string tagValue)
        {
            try
            {
                if (!CheckProperty(tag))
                {
                    return;
                }

                byte[] messageData = null;

                if (connectedSockets != null)
                {
                    lock (connectedSockets)
                    {
                        foreach (AsyncSocket socket in connectedSockets)
                        {
                            RemoteClient client = socket.GetRemoteClient();
                            if (client.IsAuthenticated && client.Properties != null)
                            {
                                MessagePropertyChanged changed = null;
                                foreach (String t in client.Properties)
                                {
                                    if (t.Equals(tag))
                                    {
                                        if (messageData == null)
                                        {

                                            //init variable only when at least on client has it on the request list
                                            changed = new MessagePropertyChanged(tag, tagValue);
                                            WifiRemote.LogMessage("Changed property: " + tag + "|" + tagValue, WifiRemote.LogType.Debug);
                                        }
                                        SendMessageToClient(changed, socket);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WifiRemote.LogMessage(ex.Message, WifiRemote.LogType.Error);
            }
        }