Exemple #1
0
        private void HandleClientComm(object client)
        {
            var tcpClient = (TcpClient)client;

            _clientList.Add(tcpClient);

            NetworkStream clientStream = tcpClient.GetStream();

            var message = new byte[4096];

            while (true)
            {
                int bytesRead;

                try
                {
                    //blocks until a client sends a message
                    bytesRead = clientStream.Read(message, 0, 4096);
                }
                catch
                {
                    //a socket error has occured
                    break;
                }

                if (bytesRead == 0)
                {
                    //the client has disconnected from the server
                    break;
                }

                //message has successfully been received
                var    encoder       = new UTF8Encoding();
                string messageString = encoder.GetString(message, 0, bytesRead);

                foreach (string theMessage in messageString.Split('\0'))
                {
                    Console.WriteLine(theMessage);
                    if (TcpMessageReceived != null)
                    {
                        var args = new TcpMessageReceivedEventArgs
                        {
                            RemoteClient = tcpClient,
                            Message      = theMessage,
                        };
                        TcpMessageReceived(this, args);
                    }
                }
            }
            tcpClient.Close();
        }
Exemple #2
0
        //public FeedbackHandler(CurrentSession CS)
        //{
        //    cs = CS;
        //}
        #region ICommands Members

        public void Execute(object param = null)
        {
            try
            {
                if (param != null && param is TcpMessageReceivedEventArgs)
                {
                    TcpMessageReceivedEventArgs arg = param as TcpMessageReceivedEventArgs;

                    List <string> message = arg.Message.Split('|').ToList();

                    if (message.Count == 2)
                    {
                        if (int.Parse(message[0]) == (decimal)ClipOption.Load)
                        {
                            CurrentSession.Player.LoadClip(message[1]);
                        }
                        else if (int.Parse(message[0]) == (decimal)ClipOption.Play)
                        {
                            CurrentSession.Player.PlayClip();
                        }
                        else if (int.Parse(message[0]) == (decimal)ClipOption.Pause)
                        {
                            CurrentSession.Player.PauseClip();
                        }
                        else if (int.Parse(message[0]) == (decimal)ClipOption.Reset)
                        {
                            CurrentSession.Player.ResetClip();
                        }
                        else if (int.Parse(message[0]) == (decimal)ClipOption.Eject)
                        {
                            CurrentSession.Player.EjectClip();
                        }

                        CurrentSession.Player.ConfirmDone(arg.Message);
                    }

                    //                    player.EndServerSession();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #3
0
 private void HandleFeedback(object sender, TcpMessageReceivedEventArgs args)
 {
     FeedbackHandler.Execute(args);
 }