private void OnMessage(object sender, MessageRecieveEventArgs eventArgs)
        {
            var address = eventArgs.Handler.GetRemoteAddress();

            if (address != null)
            {
                Console.WriteLine("New message from {0}: {1}", address, eventArgs.Message);
            }

            try
            {
                if (eventArgs.Message.Length == 0) //ETB keep alive packet
                {
                    //send keep alive back
                    ConnectionEndpoint.SendFromServer(eventArgs.Handler, String.Empty);
                }
                else
                {
                    BehaviorChooser.HandleMessage((dynamic)XmlMessageConverter.ToObject(eventArgs.Message), this,
                                                  eventArgs.Handler);
                }
            }
            catch (Exception e)
            {
                ConsoleDebug.Error(e.Message);
            }

            //ConnectionEndpoint.SendFromServer(eventArgs.Handler, eventArgs.Message);
        }
Ejemplo n.º 2
0
        private void OnMessageReceive(object sender, MessageRecieveEventArgs eventArgs)
        {
            var socket = eventArgs.Handler as Socket;

            if (eventArgs.Message.Length > 0) //the message is not the keepalive packet
            {
                ConsoleDebug.Message("New message from: " + socket.GetRemoteAddress() + "\n" + eventArgs.Message);
                messageHandler.HandleMessage((dynamic)XmlMessageConverter.ToObject(eventArgs.Message));
            }
        }
Ejemplo n.º 3
0
        private void OnMessageReceive(object sender, MessageRecieveEventArgs eventArgs)
        {
            var socket = eventArgs.Handler as Socket;

            if (eventArgs.Message.Length > 0) //the message is not the keepalive packet
            {
                ConsoleDebug.Message("New message from:" + socket.GetRemoteAddress() + "\n" + eventArgs.Message);
                messageHandler.PrintBoard();
                try
                {
                    messageHandler.HandleMessage((dynamic)XmlMessageConverter.ToObject(eventArgs.Message), socket);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
        }