API reference / @jsprismarine/raknet / RakNetSession
Class: RakNetSession
Defined in: raknet/src/Session.ts:108
Constructors
Constructor
new RakNetSession(
listener,mtuSize,rinfo,guid,role?):Session
Defined in: raknet/src/Session.ts:213
Parameters
listener
mtuSize
number
rinfo
RemoteInfo
guid
bigint
role?
RakNetRole = RakNetRole.SERVER
Returns
Session
Properties
guid
readonlyguid:bigint
Defined in: raknet/src/Session.ts:217
rinfo
readonlyrinfo:RemoteInfo
Defined in: raknet/src/Session.ts:216
role
readonlyrole:RakNetRole=RakNetRole.SERVER
Defined in: raknet/src/Session.ts:218
Methods
close()
close():
void
Defined in: raknet/src/Session.ts:1344
Queues the goodbye. Tears nothing down on its own - disconnect is what moves the session, and this is only the message it sends on the way.
Returns
void
disconnect()
disconnect(
reason?):void
Defined in: raknet/src/Session.ts:1367
Hangs up, and keeps the session alive until the peer has acknowledged it.
The goodbye is reliable, which buys nothing if the session is destroyed in the same breath: it would go out once, and a lost datagram would take the message with it - along with whatever was framed beside it, which for a kick is the DisconnectPacket carrying the reason. The peer would then sit out its own ten second timeout and show the player nothing. So the session moves to SessionStatus.DISCONNECTING and is forgotten by update once the acknowledgment lands, which is RakNet's DISCONNECT_ASAP: the system stays in the list until IsOutgoingDataWaiting goes false.
Parameters
reason?
string = 'client disconnect'
reported to whoever owns the session; never sent to the peer.
Returns
void
See
https://github.com/facebookarchive/RakNet/blob/master/Source/RakPeer.cpp#L3565
disconnectImmediate()
disconnectImmediate(
reason?):void
Defined in: raknet/src/Session.ts:1382
Forgets the session at once, with no goodbye and no wait for one.
RakNet's CloseConnectionInternal(..., sendDisconnectionNotification=false, performImmediate=true): what a timeout does, and what a socket being torn down out from under a session has to do, since nothing will be left ticking to finish a linger.
Parameters
reason?
string = ...
defaults to the one the pending disconnect was started with.
Returns
void
getAddress()
getAddress():
InetAddress
Defined in: raknet/src/Session.ts:1483
Returns the address object created for this session.
Returns
getListener()
getListener():
RakNetPeer
Defined in: raknet/src/Session.ts:1451
Returns
getMTU()
getMTU():
number
Defined in: raknet/src/Session.ts:1478
Returns the maxmium transfer unit for this connection.
Returns
number
the UDP adjusted.
getRetransmissionCount()
getRetransmissionCount():
number
Defined in: raknet/src/Session.ts:1464
Counts reliable messages resent after a NACK or retransmission deadline.
Returns
number
getRoundTripSampleCount()
getRoundTripSampleCount():
number
Defined in: raknet/src/Session.ts:1469
Counts valid ACK samples folded into the RTT estimate.
Returns
number
getRTT()
getRTT():
number|null
Defined in: raknet/src/Session.ts:1459
The smoothed round trip time in milliseconds, or null before the first acknowledgment has been measured.
Returns
number | null
getState()
getState():
number
Defined in: raknet/src/Session.ts:1416
Returns
number
handle()
handle(
buffer):void
Defined in: raknet/src/Session.ts:292
Parameters
buffer
Buffer
Returns
void
handleConnectedPing()
handleConnectedPing(
buffer):Promise<Frame>
Defined in: raknet/src/Session.ts:938
Parameters
buffer
Buffer
Returns
Promise<Frame>
handleConnectionRequest()
handleConnectionRequest(
buffer):Promise<Frame>
Defined in: raknet/src/Session.ts:849
Parameters
buffer
Buffer
Returns
Promise<Frame>
handleFragment()
handleFragment(
frame):void
Defined in: raknet/src/Session.ts:955
Parameters
frame
Returns
void
isActive()
isActive():
boolean
Defined in: raknet/src/Session.ts:1420
Returns
boolean
isClosing()
isClosing():
boolean
Defined in: raknet/src/Session.ts:1435
Whether the session is on its way out, whether or not it has got there yet.
The guard every teardown path shares: a session lingering in SessionStatus.DISCONNECTING has already said what it had to say, and must not be sent through any of it a second time.
Returns
boolean
isDisconnected()
isDisconnected():
boolean
Defined in: raknet/src/Session.ts:1424
Returns
boolean
isHandshaking()
isHandshaking():
boolean
Defined in: raknet/src/Session.ts:1447
Whether the session exists but has not finished the connected handshake.
RakNet splits this into UNVERIFIED_SENDER and HANDLING_CONNECTION_REQUEST; there is one state here because nothing needs to tell them apart. What needs the question is the offline handler, deciding whether a repeated OpenConnectionRequest2 is a duplicate whose reply was lost - which it can only be while the handshake is still running.
Returns
boolean
isOlderOrderedFrame()
isOlderOrderedFrame(
newIndex,currentIndex,maxValue?):boolean
Defined in: raknet/src/Session.ts:664
Determines whether a packet is older than expected, handling wraparound.
Parameters
newIndex
number
currentIndex
number
maxValue?
number = MAX_TRIAD_VALUE
Returns
boolean
See
https://github.com/facebookarchive/RakNet/blob/master/Source/ReliabilityLayer.cpp#L2901-L2920
sendConnectedPing()
sendConnectedPing():
void
Defined in: raknet/src/Session.ts:925
Sends a keepalive. RakNet's client pings on a timer so a connection that is idle in both directions still produces traffic before SESSION_TIMEOUT_MS elapses.
Returns
void
See
https://github.com/facebookarchive/RakNet/blob/master/Source/RakPeer.cpp#L5971
sendConnectionRequest()
sendConnectionRequest(
clientGuid):void
Defined in: raknet/src/Session.ts:877
Opens the connected handshake, the client half of handleConnectionRequest.
Called once the offline exchange has agreed an MTU and the session exists. Reliable ordered and immediate for the same reason the server's reply is: losing it stalls everything until the retransmission timer fires.
Parameters
clientGuid
bigint
our own guid, not guid, which holds the remote's.
Returns
void
sendFrame()
sendFrame(
frame,priority?):void
Defined in: raknet/src/Session.ts:675
Parameters
frame
priority?
RakNetPriority = RakNetPriority.NORMAL
Returns
void
sendFrameQueue()
sendFrameQueue():
void
Defined in: raknet/src/Session.ts:1077
Returns
void
update()
update(
timestamp?):void
Defined in: raknet/src/Session.ts:244
Parameters
timestamp?
number = ...
a reading of monotonicNow, defaulting to one taken here.
Every deadline this compares against is on that clock, so a caller passing Date.now() is not merely imprecise: epoch milliseconds beside process-relative ones expire every retransmission and every reassembly at once and time the session out on the first pass where it is idle. Pass a value only to update several sessions against one instant, or to drive time forward in a test.
Returns
void