[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / modules/network

# modules/network

## Classes

- [ServerNetworking](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/network/classes/ServerNetworking.md)

## Interfaces

### Networking

Defined in: [packages/prismarine/src/modules/network.ts:79](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L79)

What the `prismarine:network` token resolves to: the server's network front
door. The listener binds when [Networking.start](#start) is called — the bind
address and port arrive with `Server.bootstrap`, after the kernel has started
— and stays up across a `Server.reload`; only [Networking.kill](#kill) takes
it down.

#### Methods

##### admitInputs()

> **admitInputs**(`budget?`): `number`

Defined in: [packages/prismarine/src/modules/network.ts:137](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L137)

The input step: applies the input-lane packets and player removals held since the last
one, in arrival order. A no-op before [Networking.start](#start).

###### Parameters

###### budget?

`number`

The most inputs to apply; the rest wait for the next step, in order.

###### Returns

`number`

How many inputs were applied.

##### getJavaPort()

> **getJavaPort**(): `number` \| `undefined`

Defined in: [packages/prismarine/src/modules/network.ts:126](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L126)

The TCP port Java Edition clients connect to, which is the system's pick when `java-port`
is 0.

###### Returns

`number` \| `undefined`

The port, or undefined while `java-enabled` is off or before [Networking.start](#start).

##### getListener()

> **getListener**(): [`RakNetListenerLike`](https://jsprismarine.dev/api/@jsprismarine/raknet/index.md#raknetlistenerlike) \| `undefined`

Defined in: [packages/prismarine/src/modules/network.ts:105](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L105)

The RakNet listener, for what the transport seam does not cover: the query protocol's
replies go out through its socket.

###### Returns

[`RakNetListenerLike`](https://jsprismarine.dev/api/@jsprismarine/raknet/index.md#raknetlistenerlike) \| `undefined`

The listener, or undefined before [Networking.start](#start) or with RakNet off.

##### getServerName()

> **getServerName**(): [`ServerName`](https://jsprismarine.dev/api/@jsprismarine/raknet/classes/ServerName.md) \| `undefined`

Defined in: [packages/prismarine/src/modules/network.ts:112](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L112)

RakNet's server name, which encodes the unconnected pong from the [getServerStatus](#getserverstatus)
and the ports RakNet bound.

###### Returns

[`ServerName`](https://jsprismarine.dev/api/@jsprismarine/raknet/classes/ServerName.md) \| `undefined`

The server name, or undefined before [Networking.start](#start).

##### getServerStatus()

> **getServerStatus**(): `ServerStatus`

Defined in: [packages/prismarine/src/modules/network.ts:119](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L119)

What every transport advertises about the server: MOTD, version and player counts. It
exists before [Networking.start](#start), so a change made earlier shows once the
transports listen.

###### Returns

`ServerStatus`

##### holdIntent()

> **holdIntent**(`session`, `intent`): `Promise`\<`void`\>

Defined in: [packages/prismarine/src/modules/network.ts:147](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L147)

Runs an intent the server makes on a player's behalf as the player's client's own: an input
intent is held under the player's connection, behind the inputs the client sent, for the
next input step. Nothing runs before [Networking.start](#start).

###### Parameters

###### session

[`PlayerSession`](https://jsprismarine.dev/api/@jsprismarine/prismarine/player/PlayerSession/classes/PlayerSession.md)

The player's session.

###### intent

[`Intent`](https://jsprismarine.dev/api/@jsprismarine/prismarine/input/Intent/index.md#intent)\<keyof [`IntentPayloads`](https://jsprismarine.dev/api/@jsprismarine/prismarine/input/Intent/index.md#intentpayloads)\>

The intent.

###### Returns

`Promise`\<`void`\>

Settles once the intent was applied.

##### isInboundSettled()

> **isInboundSettled**(): `boolean`

Defined in: [packages/prismarine/src/modules/network.ts:153](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L153)

Whether every frame received so far has been handled, or waits behind an input held for
the next input step. True before [Networking.start](#start).

###### Returns

`boolean`

##### kill()

> **kill**(): `void`

Defined in: [packages/prismarine/src/modules/network.ts:98](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L98)

Closes every transport, dropping every session with them. A no-op before
[Networking.start](#start), so an early shutdown has nothing to do here.

###### Returns

`void`

##### pollInbound()

> **pollInbound**(): `number`

Defined in: [packages/prismarine/src/modules/network.ts:129](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L129)

Hands worker-delivered network records to the game thread at the end of a tick.

###### Returns

`number`

##### replayInboundRecord()?

> `optional` **replayInboundRecord**(`record`, `tickOffset?`): `Promise`\<`void`\>

Defined in: [packages/prismarine/src/modules/network.ts:92](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L92)

Replays one accepted packet through the connected session's handler path.

###### Parameters

###### record

[`InboundPacketRecord`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/InboundPacketTrace/index.md#inboundpacketrecord)

###### tickOffset?

`number`

###### Returns

`Promise`\<`void`\>

##### start()

> **start**(`address`, `port`): `Promise`\<`void`\>

Defined in: [packages/prismarine/src/modules/network.ts:89](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L89)

Binds every enabled transport and wires inbound traffic to the packet dispatcher, and
resolves once every transport listens.

###### Parameters

###### address

`string`

The address to bind.

###### port

`number`

The port to bind.

###### Returns

`Promise`\<`void`\>

###### Throws

When the config enables no transport, so no client could connect, or when
an enabled transport cannot listen. The error names the transport, the port and the cause,
and every transport that did start is closed again.

## Functions

### networkModule()

> **networkModule**(`networking`): [`Module`](https://jsprismarine.dev/api/@jsprismarine/kernel/index.md#module)

Defined in: [packages/prismarine/src/modules/network.ts:932](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/network.ts#L932)

Provides the [Networking](#networking) service as `prismarine:network`. The module
neither starts nor stops the listener: the bind address and port arrive with
`Server.bootstrap(ip, port)` after the kernel has started, and the listener
outlives a kernel restart (`Server.reload` never rebinds), so the server
drives [Networking.start](#start) and [Networking.kill](#kill) at the exact
points `bootstrap` and `shutdown` always did.

#### Parameters

##### networking

[`Networking`](#networking)

The networking the server constructed, so its listener is
reachable before the kernel starts.

#### Returns

[`Module`](https://jsprismarine.dev/api/@jsprismarine/kernel/index.md#module)

The module to register on the kernel.
