Esempio n. 1
0
        /// <summary>
        /// Send contents of SendingActions queue to the server when ready.
        /// </summary>
        public void Update()
        {
            if (SendingActions.Count > 0)
            {
                if (!server.Connected)
                {
                    server = new TcpClient();
                    server.Connect(serverEndPoint);
                }

                System.Diagnostics.Debug.WriteLine("SendingActions > 0.");

                NetworkStream sendStream = server.GetStream();

                try
                {
                    while (SendingActions.Count > 0)
                    {
                        byte[] buffer = SendingActions.Dequeue().ToBytes();
                        sendStream.Write(buffer, 0, buffer.Length);
                    }
                }
                catch (System.IO.IOException ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    if (SendingActions.Count > 0)
                    {
                        System.Diagnostics.Debug.WriteLine(SendingActions.Peek().DebugText());
                    }
                    throw;
                }

                sendStream.Close();
                sendStream.Dispose();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a new NetWrapper object to the SendingActions queue.
        /// </summary>
        /// <param name="netObject">Payload data to wrap and add to the SendingActions queue.</param>
        public void EnqueueSend(Payload netObject)
        {
            NetWrapper action = new NetWrapper(Categories.NetMouseState, Originator, netObject);

            SendingActions.Enqueue(action);
        }