Skip to content
Auto
Products

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.IDisposable

Inheritance: object → NamedPipeClient

One instance serves one request at a time and is not safe for concurrent use. Use NamedPipeClientPool to send requests from several threads.

Initializes a new instance of the NamedPipeClient class.

public NamedPipeClient(string pipeName)
  • pipeName string
    The name of the pipe to connect to.

Gets a value indicating whether the connection is believed to be alive.

public bool IsConnected { get; }

bool

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.

Gets a value indicating whether the client has been disposed.

public bool IsDisposed { get; }

bool

Gets the name of the pipe the client connects to.

public string PipeName { get; }

string

Opens the connection and agrees an encoding with the server. Returns at once when the client is already connected.

public void Connect()

Opens the connection and agrees an encoding with the server. Returns at once when the client is already connected.

public void Connect(int timeout)
  • timeout int
    How long to wait for the server, in milliseconds. Default: 100.

Opens the connection and agrees an encoding with the server. Returns at once when the client is already connected.

public Task ConnectAsync()

Task

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)
  • timeout int
    How long to wait for the server, in milliseconds. Default: 100.
  • token CancellationToken
    The token that cancels waiting for the server.

Task

Closes the connection. The instance cannot be connected again.

public virtual void Dispose()

Sends the given bytes and returns the bytes that come back.

public Task<byte[]> SendBytesAsync(string address, byte[] message)
  • address string
    The address naming the operation. It must not start with --.
  • message byte[]

Task<byte[]>

Whatever readResponse returns.

  • NotSupportedException - The connection agreed on an encoding older than version 3, which carries text only.

A separate name rather than an overload of SendRequestAsync(string, string), so that a call passing a plain null keeps compiling.

Sends a request and waits for the response.

public string SendRequest(string address, string message)
  • address string
    The address naming the operation. It must not start with --.
  • message string
    The message to send.

string

The response text, which is empty when the handler set no response.

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)
  • address string
    The address naming the operation. It must not start with --.
  • writeMessage Func<Stream, Task>
    Writes the request body.
  • readResponse Func<Stream, Task<T>>
    Reads the response body.

Task<T>

Whatever readResponse returns.

  • NotSupportedException - The connection agreed on an encoding older than version 3, which carries text only.

Sends a request and waits for the response.

public Task<string> SendRequestAsync(string address, string message)
  • address string
    The address naming the operation. It must not start with --.
  • message string
    The message to send.

Task<string>

The response text, which is empty when the handler set no response.