Table of Contents

Class TcpFactory<TRoot>

Namespace
MarymoorStudios.Core.Rpc.Net
Assembly
MarymoorStudios.Core.Rpc.Net.dll

Establishes a scope for incoming and outgoing TCP-based channels.

public sealed class TcpFactory<TRoot> : IPromiseDisposable where TRoot : AServer<TRoot>

Type Parameters

TRoot

The type of the root object exposed on all connection (incoming and outgoing) within the scope of this factory.

Inheritance
TcpFactory<TRoot>
Implements
Inherited Members

Remarks

Enables the creation of incoming listening sockets for receiving network connections from remote parties (potentially using different network protocols and/or endpoints).

Enables the establishment of outgoing socket to connect to remote parties.

A TcpFactory<TRoot> instance represents a set of such incoming and outgoing connections that can be torn down collectively (by disposing the factory instance).

Constructors

TcpFactory(TcpFactoryConfig, MemoryPool<byte>, ILoggerFactory, Proxy<TRoot>)

Creates a new TCP scope for incoming and outgoing connections.

public TcpFactory(TcpFactoryConfig config, MemoryPool<byte> pool, ILoggerFactory loggerFactory, Proxy<TRoot> root)

Parameters

config TcpFactoryConfig

The configuration policy for this TCP scope.

pool MemoryPool<byte>

The memory pool from which to allocate memory for network operations.

loggerFactory ILoggerFactory

The logger factory to log to.

root Proxy<TRoot>

The root object to be exposed to all connections (incoming and outgoing).

Methods

Connect<TProxy, TServer>(IPEndPoint, CancellationToken)

Create a new outgoing connection within this TCP scope.

public TProxy Connect<TProxy, TServer>(IPEndPoint endpoint, CancellationToken cancel = default) where TProxy : Proxy<TServer>, IProxy<TProxy, TServer> where TServer : AServer<TServer>

Parameters

endpoint IPEndPoint

The remote endpoint to connect to.

cancel CancellationToken

A (optional) cancellation that can be used to terminate this connection independently of the rest of the TCP scope.

Returns

TProxy

The remote root

Type Parameters

TProxy

The type of the expected remote root.

TServer

The server type of TProxy.

DisposeAsync()

public Promise DisposeAsync()

Returns

Promise

Listen(IPEndPoint, bool)

Create a new incoming listening endpoint for this TCP scope.

public Promise<TcpListener> Listen(IPEndPoint endpoint, bool allowReuse = false)

Parameters

endpoint IPEndPoint

The endpoint on which to listen.

allowReuse bool

If true, then allow the port to be rebound without TIME_WAIT.

Returns

Promise<TcpListener>

Resolves to a TcpListener for controlling the lifetime of the listening endpoint.