Ejemplo n.º 1
0
        private void OnDataReceived(IAsyncResult asyn)
        {
            try
            {
                int iRx = 0;
                iRx = socket.EndReceiveFrom(asyn, ref client);

                char[] chars          = new char[iRx - 1];
                System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
                int charLen           = d.GetChars(dataBuffer,
                                                   0, iRx - 1, chars, 0);
                String szData = new System.String(chars);

                if (szData[0].Equals('*'))
                {
                    if (szData[1].Equals('C'))
                    {
                        string id = szData.Substring(2);
                        if (!id.Equals(clientID))
                        {
                            clientID = id;
                            SendData("A\n");
                            TouchPal.Debug("Client (" + id + ") connected.");
                            manager.ClientConnected();
                        }
                    }
                    if (szData[1].Equals('R') && manager != null)
                    {
                        manager.ResetControls();
                        SendData("A\n");
                    }
                }
                else if (manager != null)
                {
                    string[] controlUpdates = szData.Split(new Char[] { ':' });
                    foreach (string controlUpdate in controlUpdates)
                    {
                        string[] values = controlUpdate.Split(new Char[] { '=' });
                        if (values.Count() == 2)
                        {
                            try
                            {
                                int networkID = Convert.ToInt32(values[0]);
                                manager.UpdateControl(networkID, values[1]);
                                SendData("A\n");
                            }
                            catch (FormatException fe)
                            {
                                TouchPal.Error("Bad network id value (" + values[0] + ") received from client - " + fe.Message);
                            }
                        }
                    }
                }
                WaitForData();
            }
            catch (SocketException se)
            {
                Console.WriteLine(se.Message);
            }
        }
Ejemplo n.º 2
0
        private void OnDataReceived(IAsyncResult asyn)
        {
            try
            {
                int iRx = 0;
                iRx = clientSocket.EndReceive(asyn);

                char[] chars          = new char[iRx + 1];
                System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
                int charLen           = d.GetChars(dataBuffer,
                                                   0, iRx, chars, 0);
                String szData = new System.String(chars);

                if (szData[0].Equals('*'))
                {
                    if (szData[1].Equals('Q'))
                    {
                        clientSocket.Close();
                        WaitForConnect();
                    }
                    else if (szData[1].Equals('R') && manager != null)
                    {
                        manager.ResetControls();
                    }
                }
                else if (manager != null)
                {
                    string[] controlUpdates = szData.Split(new Char[] { ':' });
                    foreach (string controlUpdate in controlUpdates)
                    {
                        string[] values = controlUpdate.Split(new Char[] { '=' });
                        if (values.Count() == 2)
                        {
                            try
                            {
                                int networkID = Convert.ToInt32(values[0]);
                                manager.UpdateControl(networkID, values[1]);
                            }
                            catch (FormatException fe)
                            {
                                TouchPal.Error("Bad network id value (" + values[0] + ") received from client - " + fe.Message);
                            }
                        }
                    }
                }
                WaitForData();
            }
            catch (ObjectDisposedException)
            {
                WaitForConnect();
            }
            catch (SocketException se)
            {
                Console.WriteLine(se.Message);
            }
        }
Ejemplo n.º 3
0
 void IAction.Execute(ControlManager manager)
 {
     manager.ResetControls();
 }