Table of Contents

Class TcpMessageListener

Namespace
VpnHood.Core.Client.VpnServices.Abstractions.Messaging
Assembly
VpnHood.Core.Client.VpnServices.Abstractions.dll

Represents the VPN service's side of the loopback TCP channel: it listens on an IPv4 loopback port the system picks, makes a 128-bit key, and publishes both in the config folder, as vpn.api.json, for TcpMessageClient to find.

public sealed class TcpMessageListener : IMessageListener, IDisposable
Inheritance
TcpMessageListener
Implements
Inherited Members

Remarks

Each message goes as its length, a little-endian 32-bit integer, then its bytes, up to 16,777,215 bytes; a connection's first message must be the key.

Constructors

TcpMessageListener(string)

Initializes a new instance of the TcpMessageListener class, listening at once, and publishes its endpoint and key.

public TcpMessageListener(string configFolder)

Parameters

configFolder string

The VPN service's config folder.

Exceptions

SocketException

It could not listen.

IOException

It could not publish its file.

Properties

ApiEndPoint

Gets the endpoint it listens on now, which changes where it has to listen anew.

public IPEndPoint ApiEndPoint { get; }

Property Value

IPEndPoint

Methods

Dispose()

Stops listening and tries to delete the published file.

public void Dispose()

Start(MessageHandler, CancellationToken)

Starts listening: each request goes to the handler, and the bytes it returns are the answer.

public Task Start(MessageHandler messageHandler, CancellationToken cancellationToken)

Parameters

messageHandler MessageHandler

The handler.

cancellationToken CancellationToken

The token that stops listening, for a transport that owns a loop.

Returns

Task

A task that completes when listening stops, or, for a transport with no loop, once it has begun.

Remarks

The transport owns connections, accepting them and, where it has any, authentication. A transport without a loop stops on Dispose(), which the caller must call either way.