Table of Contents

Class LocalTcpListener

Namespace
VpnHood.Net.TcpStack
Assembly
VpnHood.Net.TcpStack.dll

Provides a listener of a LocalTcpStack: it queues the connections that complete their handshake until they are accepted, the way TcpListener does for sockets.

public sealed class LocalTcpListener : ITcpListener, IDisposable
Inheritance
LocalTcpListener
Implements
Inherited Members

Remarks

A full queue (AcceptQueueCapacity) closes a new connection instead.

Properties

IsAny

Gets a value indicating whether this is the listener of ListenAny().

public bool IsAny { get; }

Property Value

bool

LocalEndPoint

Gets the endpoint this listener takes connections to, or null for the listener of ListenAny(), which takes the connections no endpoint listener takes.

public IpEndPointValue? LocalEndPoint { get; }

Property Value

IpEndPointValue?

Methods

AcceptAllAsync(CancellationToken)

Accepts connections as they complete their handshake, until the listener is stopped.

public IAsyncEnumerable<LocalTcpClient> AcceptAllAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

IAsyncEnumerable<LocalTcpClient>

The accepted connections; the caller owns each and disposes it.

Exceptions

OperationCanceledException

cancellationToken was canceled.

AcceptAsync(CancellationToken)

Accepts the next connection that completes its handshake.

public ValueTask<LocalTcpClient> AcceptAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask<LocalTcpClient>

A task whose result is the accepted connection, which the caller owns and disposes.

Exceptions

OperationCanceledException

cancellationToken was canceled.

ChannelClosedException

The listener is stopped.

Dispose()

Stops the listener, as Stop() does.

public void Dispose()

Stop()

Stops the listener: ends its accepts, closes the connections in its queue, and leaves the stack, so a new listener can take its endpoint. A handshake under way for it is closed when it completes; connections already accepted stay open. Calling it again does nothing.

public void Stop()