Table of Contents

Class ServerFactory

Namespace
Microsoft.ServiceHub.Framework
Assembly
Microsoft.ServiceHub.Framework.dll

A static class for creating named pipe servers.

public static class ServerFactory
Inheritance
ServerFactory
Inherited Members

Methods

ConnectAsync(string, ClientOptions, CancellationToken)

Connects to an IPC pipe that was created with Create(Func<Stream, Task>, ServerOptions).

public static Task<Stream> ConnectAsync(string pipeName, ServerFactory.ClientOptions options, CancellationToken cancellationToken)

Parameters

pipeName string

A fully-qualified pipe name, including the path. On Windows the prefixed path should be \.\pipe</code>.

options ServerFactory.ClientOptions

Options that can influence how the IPC pipe is connected to.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Stream>

The duplex stream established over the pipe.

ConnectAsync(string, CancellationToken)

Connects to an IPC pipe that was created with Create(Func<Stream, Task>, ServerOptions).

public static Task<Stream> ConnectAsync(string pipeName, CancellationToken cancellationToken)

Parameters

pipeName string

A fully-qualified pipe name, including the path. On Windows the prefixed path should be \.\pipe</code>.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Stream>

The duplex stream established over the pipe.

Create(Func<Stream, Task>, ServerOptions)

Creates an IPC server.

public static IIpcServer Create(Func<Stream, Task> onConnectedCallback, ServerFactory.ServerOptions options = default)

Parameters

onConnectedCallback Func<Stream, Task>

Callback function to be run whenever a client connects to the server. This may be called concurrently if multiple clients connect. The delegate may choose to return right away while still using the Stream or to complete only after finishing communication with the client.

options ServerFactory.ServerOptions

IPC server options.

Returns

IIpcServer

The server, which includes a means to obtain its pipe name and monitor for completion.

CreateAsync(string, TraceSource?, Func<Stream, Task>)

Creates a named pipe server.

[Obsolete("Use Create instead.")]
public static Task<(IDisposable Server, string ServerName)> CreateAsync(string pipeName, TraceSource? logger, Func<Stream, Task> onConnectedCallback)

Parameters

pipeName string

The name of the server. Typically just the result of calling ToString() on the result of NewGuid(). This should not include path separators.

logger TraceSource

The logger for the server.

onConnectedCallback Func<Stream, Task>
Callback function to be run whenever a client connects to the server. This may be called concurrently if multiple clients connect. The delegate may choose to return right away while still using the Stream or to complete only after finishing communication with the client.

Returns

Task<(IDisposable Server, string ServerName)>

A tuple where Server is disposable to shut down the pipe, and ServerName is the pipe name as the client will need to access it. It implements IAsyncDisposable. ServerName will typically be the same as pipeName on Windows, but on mac/linux it will have a path prepended to it.

PrependPipePrefix(string)

Prepends the OS-specific prefix to a simple pipe name.

public static string PrependPipePrefix(string leafPipeName)

Parameters

leafPipeName string

The simple pipe name. This should not include a path.

Returns

string

The fully-qualified, OS-specific pipe name.