Beispiel #1
0
        //public FeedbackHandler(FantasyServiceAgent fan)
        //{
        //    fantasy = fan;
        //}
        #region ICommands Members

        public void Execute(object param = null)
        {
            try
            {
                if (param != null && param is TcpMessageReceivedEventArgs)
                {
                    TcpMessageReceivedEventArgs arg = param as TcpMessageReceivedEventArgs;
                    log.Trace("\nHANDLING EVENT MESSAGE {0}", arg.Message);
                    Console.WriteLine("*** ROUTING TO {0}  ***", arg.Message);
                    int route;
                    if (arg.Message.Contains("game"))
                    {
                        route = int.Parse(arg.Message.Substring(4));
                        route--;
                        //rc.SetRoute("274", route.ToString());
                        rc.SetRoute("8", route.ToString());
                    }
                    else if (arg.Message.Contains("fantasy"))
                    {
                        //CurrentSession.Fantasy.ReloadTopPlayers();
                        //CurrentSession.Fantasy.SetTopPlayers();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                log.Error("ERROR HANDING THE FEEDBACK");
            }
        }
Beispiel #2
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();
        }
 private void HandleFeedback(object sender, TcpMessageReceivedEventArgs args)
 {
     FeedbackHandler.Execute(args);
 }