Walter.Net.Networking
ICMPSocket Constructor(IPAddress,CancellationToken)
Example 
Walter.Net.Networking Assembly > Walter.Net.Networking Namespace > ICMPSocket Class > ICMPSocket Constructor : ICMPSocket Constructor(IPAddress,CancellationToken)
the address to listen on
the cancelation token to listen to for canelation
Create a listener on a IP address and will listen to the canelation token to automatically stop the service
Syntax

Parameters

address
the address to listen on
cancellationToken
the cancelation token to listen to for canelation
Example
The sample shows how a listening instance can be used to process to start listening till shutdown
public void Listen()
{
    if (_terminate)
    {
        Shutdown();
    }
 
    _terminate = false;
    if (_cancellationToken is not null)
        _cancellationToken.Dispose();
 
    _cancellationToken = new CancellationTokenSource();
    if (_options.MonitorProtocol.HasFlag(PortAccessProtocols.TcpIp))
    {
        Task.Run(() => StartTcpListener(_cancellationToken.Token)).Forget();
    }
 
    if (_options.MonitorProtocol.HasFlag(PortAccessProtocols.Udp))
    {
        Task.Run(() => StartUdpListener(_cancellationToken.Token)).Forget();
    }
    if (_options.MonitorProtocol.HasFlag(PortAccessProtocols.ICMP))
    {
        _iCMPSockets = new List<ICMPSocket>();
        Inverse.TryResolve<ILoggerFactory>(out var factory);
        foreach (var ip in LocalNetwork.LocalIPAddresses())
        { 
            _iCMPSockets.Add(new ICMPSocket(ip,_cancellationToken.Token));
            _iCMPSockets[^1].PacketReceived += OnPinged;
            _iCMPSockets[^1].Logger = factory?.CreateLogger("Walter.Net.Networking.ICMPSocket.") ?? _logger;
            _iCMPSockets[^1].Start();
        }
    }
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

ICMPSocket Class
ICMPSocket Members
Overload List