Ejemplo n.º 1
0
        /// <summary>
        /// Callback for SendData call to server
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">The result from the server</param>
        void ac_GotMove(object sender, ResponseReceivedEventArgs e)
        {
            if (e.isError)
            {
                ReportMoveError(e.response);
            }
            else
            {
                UnLockGameboard();
                ClearStatusText();

                // As its next move, the server sends back one value - the name of the textblock which
                // is its gamepiece to play That is all we need from the server to make the move on the board
                foreach (TextBlock tb in gBoard.Children.OfType <TextBlock>())
                {
                    if (tb.Name == e.response)
                    {
                        // Play thsi piece for the server
                        tb.Text            = (this.PlayAsX) ? GAMEPIECE_0 : GAMEPIECE_X;
                        _pieceMap[tb.Name] = tb.Text;
                        break;
                    }
                }

                if (SomebodyWon)
                {
                    GameOver();
                }
            }
            _waitingOnServerMove = false;
        }
 protected void OnResponseReceived(ResponseReceivedEventArgs e)
 {
     if (ResponseReceived != null)
     {
         ResponseReceived(this, e);
     }
 }
        private void ProcessSend(SocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                Socket sock = e.UserToken as Socket;

                sock.ReceiveAsync(e);
            }
            else
            {
                ResponseReceivedEventArgs args = new ResponseReceivedEventArgs();
                args.response = e.SocketError.ToString();
                args.isError  = true;
                OnResponseReceived(args);
            }
        }
 private void ProcessConnect(SocketAsyncEventArgs e)
 {
     if (e.SocketError == SocketError.Success)
     {
         byte[] buffer = Encoding.UTF8.GetBytes(dataIn + "<EOF>");
         e.SetBuffer(buffer, 0, buffer.Length);
         Socket sock = e.UserToken as Socket;
         sock.SendAsync(e);
     }
     else
     {
         ResponseReceivedEventArgs args = new ResponseReceivedEventArgs();
         args.response = e.SocketError.ToString();
         args.isError  = true;
         OnResponseReceived(args);
     }
 }
        private void ProcessReceive(SocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                string dataFromServer = Encoding.UTF8.GetString(e.Buffer, 0, e.BytesTransferred);

                Socket sock = e.UserToken as Socket;
                sock.Shutdown(SocketShutdown.Send);
                sock.Close();

                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    ResponseReceivedEventArgs args = new ResponseReceivedEventArgs();
                    args.response = dataFromServer;
                    OnResponseReceived(args);
                });
            }
            else
            {
                throw new SocketException((int)e.SocketError);
            }
        }
Ejemplo n.º 6
0
 void ac_GotMove(object sender, ResponseReceivedEventArgs e)
 {
 }
Ejemplo n.º 7
0
 void ac_GotMove(object sender, ResponseReceivedEventArgs e)
 {
 }
        private void ProcessConnect(SocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                byte[] buffer = Encoding.UTF8.GetBytes(dataIn + "<EOF>");
                e.SetBuffer(buffer, 0, buffer.Length);
                Socket sock = e.UserToken as Socket;
                sock.SendAsync(e);
            }
            else
            {
                ResponseReceivedEventArgs args = new ResponseReceivedEventArgs();
                args.response = e.SocketError.ToString();
                args.isError = true;
                OnResponseReceived(args);

            }
        }
 protected void OnResponseReceived(ResponseReceivedEventArgs e)
 {
     if (ResponseReceived != null)
         ResponseReceived(this,e);
 }
        private void ProcessSend(SocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                Socket sock = e.UserToken as Socket;

                sock.ReceiveAsync(e);
            }
            else
            {
                ResponseReceivedEventArgs args = new ResponseReceivedEventArgs();
                args.response = e.SocketError.ToString();
                args.isError = true;
                OnResponseReceived(args);
            }
        }
        private void ProcessReceive(SocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                string dataFromServer = Encoding.UTF8.GetString(e.Buffer, 0, e.BytesTransferred);

                Socket sock = e.UserToken as Socket;
                sock.Shutdown(SocketShutdown.Send);
                sock.Close();

                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    ResponseReceivedEventArgs args = new ResponseReceivedEventArgs();
                    args.response = dataFromServer;
                    OnResponseReceived(args);
                });

            }
            else
            {
                throw new SocketException((int)e.SocketError);
            }
        }