示例#1
0
 /// <summary>
 /// Send a message by writing on the socket.
 /// </summary>
 /// <param name="msg"></param>
 public void send(CSMessage msg)
 {
     try
     {
         formatter.Serialize(tcpclient.GetStream(), msg);
     }
     catch (Exception e)
     {
         log(Severiry.ERROR, "Sending -> " + e.Message);
     }
 }
示例#2
0
        /// <summary>
        /// Process run method.
        /// </summary>
        /// <param name="token"></param>
        public void run(CancellationToken token)
        {
            while (tcpclient.Connected && !token.IsCancellationRequested)
            {
                try
                {
                    CSMessage msg = (CSMessage)formatter.Deserialize(tcpclient.GetStream());
                    switch (msg.Type)
                    {
                    case MessageType.DECONNECTION:
                        deconnetion();
                        break;

                    case MessageType.LOGIN:
                        loginHandler(this, msg);
                        break;

                    case MessageType.CHALLENGING:
                        challengerHandler(this, msg);
                        break;

                    case MessageType.STOP_GAME:
                        stopGameHandler(this, msg);
                        break;

                    case MessageType.END_GAME:
                        endGameHandler(this, msg);
                        break;

                    default:
                        handleMessage(msg);
                        break;
                    }
                }
                catch (Exception)
                {
                    if (!token.IsCancellationRequested)
                    {
                        deconnetion();
                    }
                }
            }
        }
示例#3
0
 public abstract void handleMessage(CSMessage msg);