NamedPipeClient
Namespace: TagBites.Pipes
Assembly: TagBites.Pipes.dll
Product: TagBites.Pipes v. 1.2.0
Sends requests to a NamedPipeServer on the local machine over a single connection.
public class NamedPipeClient : System.IDisposableInheritance: object → NamedPipeClient
Remarks
Section titled “Remarks”One instance serves one request at a time and is not safe for concurrent use. Use NamedPipeClientPool to send requests from several threads.
Constructors
Section titled “Constructors”NamedPipeClient(string)
Section titled “NamedPipeClient(string)”Initializes a new instance of the NamedPipeClient class.
public NamedPipeClient(string pipeName)Parameters
Section titled “Parameters”pipeNamestring
The name of the pipe to connect to.
Exceptions
Section titled “Exceptions”- ArgumentNullException -
pipeNameisnull.
Properties
Section titled “Properties”IsConnected
Section titled “IsConnected”Gets a value indicating whether the connection is believed to be alive.
public bool IsConnected { get; }Property Value
Section titled “Property Value”Remarks
Section titled “Remarks”This turns to false once a request fails or the client is disposed. A connection that the other side dropped while idle still reads as true, because a named pipe reveals that only when it is used.
IsDisposed
Section titled “IsDisposed”Gets a value indicating whether the client has been disposed.
public bool IsDisposed { get; }Property Value
Section titled “Property Value”PipeName
Section titled “PipeName”Gets the name of the pipe the client connects to.
public string PipeName { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”Connect()
Section titled “Connect()”Opens the connection and agrees an encoding with the server. Returns at once when the client is already connected.
public void Connect()Exceptions
Section titled “Exceptions”- TimeoutException - The server did not accept within the timeout.
- ObjectDisposedException - The client has been disposed.
Connect(int)
Section titled “Connect(int)”Opens the connection and agrees an encoding with the server. Returns at once when the client is already connected.
public void Connect(int timeout)Parameters
Section titled “Parameters”timeoutint
How long to wait for the server, in milliseconds. Default:100.
Exceptions
Section titled “Exceptions”- TimeoutException - The server did not accept within the timeout.
- ObjectDisposedException - The client has been disposed.
ConnectAsync()
Section titled “ConnectAsync()”Opens the connection and agrees an encoding with the server. Returns at once when the client is already connected.
public Task ConnectAsync()Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”- TimeoutException - The server did not accept within the timeout.
- ObjectDisposedException - The client has been disposed.
ConnectAsync(int, CancellationToken)
Section titled “ConnectAsync(int, CancellationToken)”Opens the connection and agrees an encoding with the server. Returns at once when the client is already connected.
public Task ConnectAsync(int timeout, CancellationToken token)Parameters
Section titled “Parameters”timeoutint
How long to wait for the server, in milliseconds. Default:100.tokenCancellationToken
The token that cancels waiting for the server.
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”- TimeoutException - The server did not accept within the timeout.
- ObjectDisposedException - The client has been disposed.
Dispose()
Section titled “Dispose()”Closes the connection. The instance cannot be connected again.
public virtual void Dispose()SendBytesAsync(string, byte[])
Section titled “SendBytesAsync(string, byte[])”Sends the given bytes and returns the bytes that come back.
public Task<byte[]> SendBytesAsync(string address, byte[] message)Parameters
Section titled “Parameters”Returns
Section titled “Returns”Whatever readResponse returns.
Exceptions
Section titled “Exceptions”- NotSupportedException - The connection agreed on an encoding older than version
3, which carries text only.
Remarks
Section titled “Remarks”A separate name rather than an overload of SendRequestAsync(string, string), so that a call passing a plain null keeps compiling.
SendRequest(string, string)
Section titled “SendRequest(string, string)”Sends a request and waits for the response.
public string SendRequest(string address, string message)Parameters
Section titled “Parameters”addressstring
The address naming the operation. It must not start with--.messagestring
The message to send.
Returns
Section titled “Returns”The response text, which is empty when the handler set no response.
Exceptions
Section titled “Exceptions”- ArgumentNullException -
addressormessageisnull. - ArgumentException -
addressstarts with--, which is reserved. - InvalidOperationException - The client is not connected.
- NamedPipeConnectionLostException - The connection broke while sending or receiving.
- NamedPipeServerRemoteException - The request handler on the server failed.
SendRequestAsync<T>(string, Func<Stream, Task>, Func<Stream, Task<T>>)
Section titled “SendRequestAsync<T>(string, Func<Stream, Task>, Func<Stream, Task<T>>)”Sends a request written by a callback and reads the response with another one, so neither side has to hold the whole payload in memory.
public Task<T> SendRequestAsync(string address, Func<Stream, Task> writeMessage, Func<Stream, Task<T>> readResponse)Parameters
Section titled “Parameters”addressstring
The address naming the operation. It must not start with--.writeMessageFunc<Stream, Task>
Writes the request body.readResponseFunc<Stream, Task<T>>
Reads the response body.
Returns
Section titled “Returns”Task<T>
Whatever readResponse returns.
Exceptions
Section titled “Exceptions”- NotSupportedException - The connection agreed on an encoding older than version
3, which carries text only.
SendRequestAsync(string, string)
Section titled “SendRequestAsync(string, string)”Sends a request and waits for the response.
public Task<string> SendRequestAsync(string address, string message)Parameters
Section titled “Parameters”addressstring
The address naming the operation. It must not start with--.messagestring
The message to send.
Returns
Section titled “Returns”The response text, which is empty when the handler set no response.
Exceptions
Section titled “Exceptions”- ArgumentNullException -
addressormessageisnull. - ArgumentException -
addressstarts with--, which is reserved. - InvalidOperationException - The client is not connected.
- NamedPipeConnectionLostException - The connection broke while sending or receiving.
- NamedPipeServerRemoteException - The request handler on the server failed.