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
TRootThe 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
configTcpFactoryConfigThe configuration policy for this TCP scope.
poolMemoryPool<byte>The memory pool from which to allocate memory for network operations.
loggerFactoryILoggerFactoryThe logger factory to log to.
rootProxy<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
endpointIPEndPointThe remote endpoint to connect to.
cancelCancellationTokenA (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
TProxyThe type of the expected remote root.
TServerThe server type of
TProxy.
DisposeAsync()
public Promise DisposeAsync()
Returns
Listen(IPEndPoint, bool)
Create a new incoming listening endpoint for this TCP scope.
public Promise<TcpListener> Listen(IPEndPoint endpoint, bool allowReuse = false)
Parameters
endpointIPEndPointThe endpoint on which to listen.
allowReuseboolIf 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.