public async void SendMessage(MessageCode msgCode, byte[] data)
        {
            Remote_Content_Show_Header header = new Remote_Content_Show_Header(msgCode, data.Length, RemoteType.Client);
            byte[] headerBytes = header.ToByte;

            try
            {
               
                    this.writer.WriteBytes(headerBytes);
                    this.writer.WriteBytes(data);

                    await this.writer.StoreAsync();

                    await this.writer.FlushAsync();
                
            }
            catch (Exception)
            {
                this.Stop();

                if (this.OnConnectionLost != null)
                {
                    this.OnConnectionLost();
                }
            }
        }
        /// <summary>
        /// Responds with a list of the running processes that have a window.
        /// </summary>
        private void HandleProcessListRequest()
        {
            RCS_Process_List_Response response =
                new RCS_Process_List_Response(this.GetProcessList(this.previewImageSize), Environment.MachineName, RemoteType.Agent);

            byte[] responseMsg = Remote_Content_Show_MessageGenerator.GetMessageAsByte(response);
            byte[] responseHeader =
                new Remote_Content_Show_Header(MessageCode.MC_Process_List_Response, responseMsg.Length, RemoteType.Agent).ToByte;

            try
            {
                this.stream.Write(responseHeader, 0, responseHeader.Length);
                this.stream.Write(responseMsg, 0, responseMsg.Length);
                this.stream.Flush();
            }
            catch
            {
            }
        }
        /// <summary>
        /// Sends a header and the given message to the remote client.
        /// </summary>
        /// <param name="msgCode">The type of message to send.</param>
        /// <param name="msg">The message to send.</param>
        /// <exception cref="IOException">
        /// There was a failure while writing to the network. -or-
        /// An error occurred when accessing the socket.</exception>
        /// <exception cref="ObjectDisposedException">
        /// The System.Net.Sockets.NetworkStream is closed. -or-
        /// There was a failure reading from the network.</exception>
        private void SendMessage(MessageCode msgCode, Remote_Content_Show_Message msg)
        {
            byte[] byteMsg = Remote_Content_Show_MessageGenerator.GetMessageAsByte(msg);
            byte[] header = new Remote_Content_Show_Header(msgCode, byteMsg.Length, RemoteType.Agent).ToByte;

            lock (this.stream)
            {
                this.stream.Write(header, 0, header.Length);
                this.stream.Write(byteMsg, 0, byteMsg.Length);
                this.stream.Flush();
            }
        }
 public void Write(byte[] messageData, MessageCode code)
 {
     Remote_Content_Show_Header header = new Remote_Content_Show_Header(code, messageData.Length, RemoteType.Configurator);
     this.stream.Write(header.ToByte, 0, Remote_Content_Show_Header.HeaderLength);
     this.stream.Write(messageData, 0, messageData.Length);
 }