Skip to content

API reference / @jsprismarine/raknet / RakNetListener

Class: RakNetListener ​

Defined in: raknet/src/ServerSocket.ts:33

The server-facing RakNet API shared by the socket and worker-backed implementations.

Extends ​

  • EventEmitter

Implements ​

Constructors ​

Constructor ​

new RakNetListener(maxConnections, _onlineMode, serverName, logger, socketBufferOptions?, datagramSendMode?, serverGuid?, source?): ServerSocket

Defined in: raknet/src/ServerSocket.ts:65

Parameters ​

maxConnections ​

number

how many sessions may exist at once; see setMaxConnections.

_onlineMode ​

boolean

accepted for compatibility and unused. RakNet has no part in Bedrock's online mode: the client never enables RakNet security, and the identity check belongs to the game layer's login.

serverName ​

ServerName

the MOTD line; the socket feeds it the guid and the bound port.

logger ​

Logger

where the socket reports.

socketBufferOptions? ​

SocketBufferOptions = {}

requested UDP buffers, which the OS may cap.

datagramSendMode? ​

DatagramSendMode = 'copy'

experimental frame-set send path; copy remains the default.

serverGuid? ​

bigint

optional identifier supplied by a worker-owning facade. Without one the socket takes the guid serverName already carries, so an IPv4 and an IPv6 socket sharing one server name answer with the same guid, and draws a fresh one only when it has none.

source? ​

DatagramSource

where datagrams come from and go; a UDP socket of its own when absent.

Returns ​

ServerSocket

Overrides ​

EventEmitter.constructor

Properties ​

serverName ​

readonly serverName: ServerName

Defined in: raknet/src/ServerSocket.ts:68

the MOTD line; the socket feeds it the guid and the bound port.

Implementation of ​

RakNetListenerLike.serverName

Methods ​

addSession() ​

addSession(rinfo, mtuSize, incomingGuid): void

Defined in: raknet/src/ServerSocket.ts:283

Parameters ​

rinfo ​

RemoteInfo

mtuSize ​

number

incomingGuid ​

bigint

Returns ​

void


allowIncomingConnections() ​

allowIncomingConnections(): boolean

Defined in: raknet/src/ServerSocket.ts:259

Used to retrieve if we are overflowing the maximum connections we can allow, value given in the constructor.

Returns ​

boolean

if we can hold new connections.

Implementation of ​

RakNetListenerLike.allowIncomingConnections


getLogger() ​

getLogger(): Logger

Defined in: raknet/src/ServerSocket.ts:302

Returns ​

Logger

Implementation of ​

RakNetListenerLike.getLogger


getMaxConnections() ​

getMaxConnections(): number

Defined in: raknet/src/ServerSocket.ts:267

Returns the maximum number of incoming connections.

Returns ​

number

the maximum connections we can allow.

Implementation of ​

RakNetListenerLike.getMaxConnections


getServerGuid() ​

getServerGuid(): bigint

Defined in: raknet/src/ServerSocket.ts:321

Returns ​

bigint

Implementation of ​

RakNetListenerLike.getServerGuid


getSessionByAddress() ​

getSessionByAddress(rinfo): RakNetSession | null

Defined in: raknet/src/ServerSocket.ts:310

Parameters ​

rinfo ​

RemoteInfo

Returns ​

RakNetSession | null

Implementation of ​

RakNetListenerLike.getSessionByAddress


getSessionByGUID() ​

getSessionByGUID(guid): RakNetSession | null

Defined in: raknet/src/ServerSocket.ts:314

Parameters ​

guid ​

bigint

Returns ​

RakNetSession | null

Implementation of ​

RakNetListenerLike.getSessionByGUID


getSessions() ​

getSessions(): RakNetSession[]

Defined in: raknet/src/ServerSocket.ts:306

Returns ​

RakNetSession[]

Implementation of ​

RakNetListenerLike.getSessions


kill() ​

kill(): void

Defined in: raknet/src/ServerSocket.ts:222

Returns ​

void

Implementation of ​

RakNetListenerLike.kill


removeSession() ​

removeSession(session, reason?): void

Defined in: raknet/src/ServerSocket.ts:290

The session has finished disconnecting and should be forgotten. Called exactly once per session, from Session.disconnect.

Parameters ​

session ​

RakNetSession

reason? ​

string

Returns ​

void

Implementation of ​

RakNetListenerLike.removeSession


sendBuffer() ​

sendBuffer(buffer, rinfo): void

Defined in: raknet/src/ServerSocket.ts:344

Parameters ​

buffer ​

Buffer

rinfo ​

RemoteInfo

Returns ​

void

Implementation of ​

RakNetListenerLike.sendBuffer


sendPacket() ​

sendPacket<T>(packet, rinfo): void

Defined in: raknet/src/ServerSocket.ts:325

Encodes and sends a packet to rinfo. Sessions never touch a socket directly - a closed or unbound one has to be the peer's problem, since only the peer knows.

Type Parameters ​

T ​

T extends Packet

Parameters ​

packet ​

T

rinfo ​

RemoteInfo

Returns ​

void

Implementation of ​

RakNetListenerLike.sendPacket


setMaxConnections() ​

setMaxConnections(allowed): void

Defined in: raknet/src/ServerSocket.ts:275

Sets the maximum number of allowed incoming connections.

Parameters ​

allowed ​

number

maximum number of connections.

Returns ​

void

Implementation of ​

RakNetListenerLike.setMaxConnections


start() ​

start(address, port): void

Defined in: raknet/src/ServerSocket.ts:96

Starts the datagram source and ticking sessions. A UDP source binds an IPv6-only socket for an IPv6 address, so the IPv4 and IPv6 listeners of one server never contend for the same traffic.

A source that cannot start, such as a socket whose port another program holds, emits error and stops. With no error listener, the error is thrown, as for any EventEmitter.

Parameters ​

address ​

string

The address to bind, IPv4 or IPv6.

port ​

number

The port to bind; 0 lets the operating system choose.

Returns ​

void

Implementation of ​

RakNetListenerLike.start