/*********************************************************************** * * Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; version 2.1 * of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, Novell, Inc. * * To contact Novell about this file by physical or electronic mail, * you may find current contact information at www.novell.com. * ***********************************************************************/ using System; using System.IO; using AppModule.InterProcessComm; namespace AppModule.NamedPipes { #region Comments /// /// Used by client applications to communicate with server ones by using named pipes. /// #endregion public sealed class ClientPipeConnection : APipeConnection { #region Comments /// /// The network name of the server where the server pipe is created. /// /// /// If "." is used as a server name then the pipe is connected to the local machine. /// #endregion private string Server = "."; #region Comments /// /// Closes a client named pipe connection. /// /// /// A client pipe connection is closed by closing the underlying pipe handle. /// #endregion public override void Close() { CheckIfDisposed(); NamedPipeWrapper.Close(this.Handle); } #region Comments /// /// Connects a client pipe to an existing server one. /// #endregion public override void Connect() { CheckIfDisposed(); this.Handle = NamedPipeWrapper.ConnectToPipe(this.Name, this.Server); } #region Comments /// /// Attempts to establish a connection to the a server named pipe. /// /// /// If the attempt is successful the method creates the /// PipeHandle object /// and assigns it to the Handle /// field.

/// This method is used when it is not known whether a server pipe already exists. ///
/// True if a connection is established. #endregion public bool TryConnect() { CheckIfDisposed(); bool ReturnVal = NamedPipeWrapper.TryConnectToPipe(this.Name, this.Server, out this.Handle); return ReturnVal; } #region Comments /// /// Creates an instance of the ClientPipeConnection assuming that the server pipe /// is created on the same machine. /// /// /// The maximum bytes to read from the client is set to be Int32.MaxValue. /// /// The name of the server pipe. #endregion public ClientPipeConnection(string name) { this.Name = name; this.Server = "."; this.maxReadBytes = Int32.MaxValue; } #region Comments /// /// Creates an instance of the ClientPipeConnection specifying the network name /// of the server. /// /// /// The maximum bytes to read from the client is set to be Int32.MaxValue. /// /// The name of the server pipe. /// The network name of the machine, where the server pipe is created. #endregion public ClientPipeConnection(string name, string server) { this.Name = name; this.Server = server; this.maxReadBytes = Int32.MaxValue; } #region Comments /// /// Object destructor. /// #endregion ~ClientPipeConnection() { Dispose(false); } } }