API reference / @jsprismarine/raknet / LoopbackSocket
Class: LoopbackSocket
Defined in: raknet/src/LoopbackSocket.ts:209
A connected RakNet pair with no sockets under it, for running a server in the same process as its client.
This is what makes single player the same code path as multiplayer rather than a reimplementation of it: the server keeps talking to a RakNetSession and cannot tell it is not on a wire, and the client keeps speaking the protocol rather than reaching into the server's state.
Example
const loopback = new LoopbackSocket(logger);
await server.bootstrap({ listener: loopback.server });
const session = await loopback.connect();Constructors
Constructor
new LoopbackSocket(
logger,options?):LoopbackSocket
Defined in: raknet/src/LoopbackSocket.ts:218
Parameters
logger
options?
LoopbackOptions = {}
Returns
LoopbackSocket
Properties
client
readonlyclient:LoopbackEndpoint
Defined in: raknet/src/LoopbackSocket.ts:211
server
readonlyserver:LoopbackEndpoint
Defined in: raknet/src/LoopbackSocket.ts:210
Methods
connect()
connect(
timeoutMs?):Promise<RakNetSession>
Defined in: raknet/src/LoopbackSocket.ts:239
Runs the connected handshake and resolves on the client's session.
Call it once whatever is listening on server has registered its handlers: openConnection fires from inside this, and a server that has not subscribed yet would miss its own connection.
Parameters
timeoutMs?
number = 5_000
Returns
Promise<RakNetSession>
kill()
kill():
void
Defined in: raknet/src/LoopbackSocket.ts:267
Returns
void