Exemple #1
0
        /// <summary>
        /// Attempts to establish a connection to the a server named pipe.
        /// </summary>
        /// <remarks>
        /// If the attempt is successful the method creates the
        /// <see cref="InterProcessComm.NamedPipes.PipeHandle">PipeHandle</see> object
        /// and assigns it to the <see cref="InterProcessComm.NamedPipes.APipeConnection.Handle">Handle</see>
        /// field.<br/><br/>
        /// This method is used when it is not known whether a server pipe already exists.
        /// </remarks>
        /// <returns>True if a connection is established.</returns>
        #endregion
        public bool TryConnect()
        {
            CheckIfDisposed();
            bool ReturnVal = NamedPipeWrapper.TryConnectToPipe(this.Name, this.Server, out this.Handle);

            return(ReturnVal);
        }
Exemple #2
0
 /// <summary>
 /// Disposes a pipe connection by closing the underlying native handle.
 /// </summary>
 /// <param name="disposing">A boolean indicating how the method is called.</param>
 #endregion
 protected void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         NamedPipeWrapper.Close(this.Handle);
     }
     disposed = true;
 }
Exemple #3
0
 /// <summary>
 /// Writes a string to the pipe connection/
 /// </summary>
 /// <param name="text">The text to write.</param>
 #endregion
 public void Write(string text)
 {
     CheckIfDisposed();
     NamedPipeWrapper.Write(Handle, text);
 }
Exemple #4
0
 /// <summary>
 /// Reads a message from the pipe connection.
 /// </summary>
 /// <remarks>
 /// See the <see cref="InterProcessComm.NamedPipes.NamedPipeWrapper.ReadBytes">NamedPipeWrapper.ReadBytes</see>
 /// method for an explanation of the message format.
 /// </remarks>
 /// <returns>The bytes read from the pipe connection.</returns>
 #endregion
 public byte[] ReadBytes()
 {
     CheckIfDisposed();
     return(NamedPipeWrapper.ReadBytes(Handle, maxReadBytes));
 }
Exemple #5
0
 /// <summary>
 /// Reads a message from the pipe connection and converts it to a string
 /// using the UTF8 encoding.
 /// </summary>
 /// <remarks>
 /// See the <see cref="InterProcessComm.NamedPipes.NamedPipeWrapper.Read">NamedPipeWrapper.Read</see>
 /// method for an explanation of the message format.
 /// </remarks>
 /// <returns>The UTF8 encoded string representation of the data.</returns>
 #endregion
 public string Read()
 {
     CheckIfDisposed();
     return(NamedPipeWrapper.Read(Handle, maxReadBytes));
 }
Exemple #6
0
 /// <summary>
 /// Writes an array of bytes to the pipe connection.
 /// </summary>
 /// <param name="bytes">The bytes array.</param>
 #endregion
 public void WriteBytes(byte[] bytes)
 {
     CheckIfDisposed();
     NamedPipeWrapper.WriteBytes(Handle, bytes);
 }
Exemple #7
0
 /// <summary>
 /// Creates a ServerPipeConnection instance and the underlying operating system handle.
 /// </summary>
 /// <param name="name">The name of the pipe.</param>
 /// <param name="outBuffer">The outbound buffer.</param>
 /// <param name="inBuffer">The inbound buffer.</param>
 /// <param name="secure">Specifies whether the pipe is secure.</param>
 /// <param name="maxReadBytes">The maximum bytes to read from clients.</param>
 /// <remarks>If the <b>secure</b> parameter is true the default security descriptor is used. The ACLs in the default security descriptor for a named pipe grant full control to the LocalSystem account, administrators, and the creator owner. They also grant read access to members of the Everyone group and the anonymous account.
 /// <br/><br/>
 /// If the <b>secure</b> parameter is false the method creates a security descriptor that grants full access to Everyone.
 /// </remarks>
 #endregion
 public ServerPipeConnection(string name, uint outBuffer, uint inBuffer, int maxReadBytes, bool secure)
 {
     this.Name         = name;
     this.Handle       = NamedPipeWrapper.Create(name, outBuffer, inBuffer, secure);
     this.maxReadBytes = maxReadBytes;
 }
Exemple #8
0
 /// <summary>
 /// Starts listening to client pipe connections.
 /// </summary>
 /// <remarks>
 /// This method will block the program execution until a client pipe attempts
 /// to establish a connection.<br/><br/>
 /// When a client named pipe is disconnected, the server one is not closed.
 /// The latter can later be reused by starting to listen again.<br/><br/>
 /// </remarks>
 #endregion
 public override void Connect()
 {
     CheckIfDisposed();
     NamedPipeWrapper.Connect(this.Handle);
 }
Exemple #9
0
 /// <summary>
 /// Closes the operating system native handle of the named pipe.
 /// </summary>
 #endregion
 public override void Close()
 {
     CheckIfDisposed();
     NamedPipeWrapper.Close(this.Handle);
 }
Exemple #10
0
 /// <summary>
 /// Disconnects a client named pipe.
 /// </summary>
 /// <remarks>
 /// When a client named pipe is disconnected, the server one is not closed.
 /// The latter can later be reused by starting to listen again.<br/><br/>
 /// In a message oriented protocol the server will disconnect the client when the
 /// response is sent and all the data is flushed. The same server named pipe
 /// could then be reused by calling the
 /// <see cref="InterProcessComm.NamedPipes.ServerPipeConnection.Connect">Connect</see> method.
 /// </remarks>
 #endregion
 public void Disconnect()
 {
     CheckIfDisposed();
     NamedPipeWrapper.Disconnect(this.Handle);
 }
Exemple #11
0
 /// <summary>
 /// Connects a client pipe to an existing server one.
 /// </summary>
 #endregion
 public override void Connect()
 {
     CheckIfDisposed();
     this.Handle = NamedPipeWrapper.ConnectToPipe(this.Name, this.Server);
 }