Skip to content

Interface: IInterfaceListening ​

说明

本页由源码中的注释生成,内容为英文。

Listening on network interfaces instead of addresses: what the entrypoints use for their interface option. The package @lakutata/netif implements it, and is the one used by default; another implementation is given in the interfaceListening option of the entrypoints.

Example ​

typescript
import type {IInterfaceListener, IInterfaceListening} from 'lakutata'
import {listenOnAll} from '@lakutata/netif'

//An implementation that writes each listener made before giving it to the entrypoint
const logged: IInterfaceListening = {
    listenOnAll: async (selectors, server, options): Promise<IInterfaceListener[]> => {
        const listeners: IInterfaceListener[] = await listenOnAll(selectors, server, options)
        for (const listener of listeners) console.log(listener.networkInterface.name, listener.addresses)
        return listeners
    }
}

Methods ​

listenOnAll() ​

listenOnAll(selectors, server, options): Promise<IInterfaceListener[]>

Listen on interfaces for a server, one listener by interface; when one cannot be listened on, the others are closed and the error is thrown. An interface that does not exist yet is listened on once it appears.

Parameters ​

selectors ​

NetworkInterfaceSelector | NetworkInterfaceSelector[]

The interfaces; several need a port other than 0.

server ​

Server

The server the connections are given to.

options ​

IInterfaceListenOptions

The port, the families, and whether the other interfaces must be refused.

Returns ​

Promise<IInterfaceListener[]>

The listeners, in the order of the interfaces.

Released under the MIT License.