Table of Contents

Interface ITcpService

Namespace
NLightning.Infrastructure.Transport.Interfaces
Assembly
NLightning.Infrastructure.dll
public interface ITcpService

Properties

ListeningTo

Gets the list of IP endpoints that the service is currently listening to for incoming connections.

List<EndPoint> ListeningTo { get; }

Property Value

List<EndPoint>

Remarks

This property provides the collection of addresses and ports actively used by the TCP listener to accept connections. The list remains updated as the service starts and stops listening to various addresses.

Methods

ConnectToPeerAsync(PeerAddress)

Establishes a connection to a peer specified by the provided address information.

Task<ConnectedPeer> ConnectToPeerAsync(PeerAddress peerAddress)

Parameters

peerAddress PeerAddress

Returns

Task<ConnectedPeer>

A task representing the asynchronous operation. The result contains a ConnectedPeer object representing the connected peer.

StartListeningAsync(CancellationToken)

Starts the TCP listener service and begins listening for incoming connections on the configured addresses.

Task StartListeningAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A token to monitor for cancellation requests, which can be used to stop listening.

Returns

Task

A task representing the asynchronous operation.

StopListeningAsync()

Stops the TCP listener service and cleans up all active listeners, ensuring that no further connections can be made.

Task StopListeningAsync()

Returns

Task

A task representing the asynchronous operation.

Events

OnNewPeerConnected

Event triggered when a new peer successfully establishes a connection.

event EventHandler<NewPeerConnectedEventArgs> OnNewPeerConnected

Event Type

EventHandler<NewPeerConnectedEventArgs>

Remarks

This event provides the means to handle actions or logic that should occur when a new peer connects to the TCP listener.