Class TcpSession
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<Packet>
org.geysermc.mcprotocollib.network.tcp.TcpSession
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,Session
- Direct Known Subclasses:
TcpClientSession,TcpServerSession
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected Stringprotected intstatic booleanControls whether non-priority packets are handled in a separate event loop -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(SessionListener listener) Adds a listener to this session.voidcallEvent(SessionEvent event) Calls an event on the listeners of this session.voidcallPacketReceived(Packet packet) Notifies all listeners that a packet was just received.voidcallPacketSent(Packet packet) Notifies all listeners that a packet was just sent.voidchannelActive(io.netty.channel.ChannelHandlerContext ctx) voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) protected voidchannelRead0(io.netty.channel.ChannelHandlerContext ctx, Packet packet) voidconnect()Connects this session to its host and port.voidconnect(boolean wait) Connects this session to its host and port.voidconnect(boolean wait, boolean transferring) Connects this session to its host and port.voiddisconnect(String reason) Disconnects the session.voiddisconnect(String reason, Throwable cause) Disconnects the session.voiddisconnect(net.kyori.adventure.text.Component reason) Disconnects the session.voiddisconnect(net.kyori.adventure.text.Component reason, Throwable cause) Disconnects the session.voidenableEncryption(PacketEncryption encryption) Enables encryption for this session.voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) io.netty.channel.ChannelintGets the compression packet length threshold for this session (-1 = disabled).intGets the connect timeout for this session in seconds.<T> TGets the value of the given flag as an instance of the given type.<T> TGets the value of the given flag as an instance of the given type.getFlags()Gets this session's set flags.getHost()Gets the host the session is connected to.Gets the listeners listening on this session.Gets the local address of the session.Gets the packet protocol of the session.intgetPort()Gets the port the session is connected to.intGets the read timeout for this session in seconds.Gets the remote address of the session.intGets the write timeout for this session in seconds.booleanChecks whether this session has a flag set.booleanReturns true if the session is connected.protected voidprotected voidrefreshReadTimeoutHandler(io.netty.channel.Channel channel) protected voidprotected voidrefreshWriteTimeoutHandler(io.netty.channel.Channel channel) voidremoveListener(SessionListener listener) Removes a listener from this session.voidSends a packet.voidsetCompressionThreshold(int threshold, boolean validateDecompression) Sets the compression packet length threshold for this session (-1 = disabled).voidsetConnectTimeout(int timeout) Sets the connect timeout for this session in seconds.<T> voidSets the value of a flag.voidSets the values for a collection of flags.voidsetReadTimeout(int timeout) Sets the read timeout for this session in seconds.voidsetWriteTimeout(int timeout) Sets the write timeout for this session in seconds.Methods inherited from class io.netty.channel.SimpleChannelInboundHandler
acceptInboundMessage, channelReadMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemovedMethods inherited from interface org.geysermc.mcprotocollib.network.Session
getCodecHelper
-
Field Details
-
USE_EVENT_LOOP_FOR_PACKETS
public static boolean USE_EVENT_LOOP_FOR_PACKETSControls whether non-priority packets are handled in a separate event loop -
host
-
port
protected int port -
disconnected
protected boolean disconnected
-
-
Constructor Details
-
TcpSession
-
-
Method Details
-
connect
public void connect()Description copied from interface:SessionConnects this session to its host and port. -
connect
public void connect(boolean wait) Description copied from interface:SessionConnects this session to its host and port. -
connect
public void connect(boolean wait, boolean transferring) Description copied from interface:SessionConnects this session to its host and port. -
getHost
Description copied from interface:SessionGets the host the session is connected to. -
getPort
public int getPort()Description copied from interface:SessionGets the port the session is connected to. -
getLocalAddress
Description copied from interface:SessionGets the local address of the session.- Specified by:
getLocalAddressin interfaceSession- Returns:
- The local address, or null if the session is not connected.
-
getRemoteAddress
Description copied from interface:SessionGets the remote address of the session.- Specified by:
getRemoteAddressin interfaceSession- Returns:
- The remote address, or null if the session is not connected.
-
getPacketProtocol
Description copied from interface:SessionGets the packet protocol of the session.- Specified by:
getPacketProtocolin interfaceSession- Returns:
- The session's packet protocol.
-
getFlags
Description copied from interface:SessionGets this session's set flags. If this session belongs to a server, the server's flags will be included in the results. -
hasFlag
Description copied from interface:SessionChecks whether this session has a flag set. If this session belongs to a server, the server's flags will also be checked. -
getFlag
Description copied from interface:SessionGets the value of the given flag as an instance of the given type. If this session belongs to a server, the server's flags will be checked for the flag as well. -
getFlag
Description copied from interface:SessionGets the value of the given flag as an instance of the given type. If this session belongs to a server, the server's flags will be checked for the flag as well. If the flag is not set, the specified default value will be returned. -
setFlag
Description copied from interface:SessionSets the value of a flag. This does not change a server's flags if this session belongs to a server. -
setFlags
Description copied from interface:SessionSets the values for a collection of flags. -
getListeners
Description copied from interface:SessionGets the listeners listening on this session.- Specified by:
getListenersin interfaceSession- Returns:
- This session's listeners.
-
addListener
Description copied from interface:SessionAdds a listener to this session.- Specified by:
addListenerin interfaceSession- Parameters:
listener- Listener to add.
-
removeListener
Description copied from interface:SessionRemoves a listener from this session.- Specified by:
removeListenerin interfaceSession- Parameters:
listener- Listener to remove.
-
callEvent
Description copied from interface:SessionCalls an event on the listeners of this session. -
callPacketReceived
Description copied from interface:SessionNotifies all listeners that a packet was just received.- Specified by:
callPacketReceivedin interfaceSession- Parameters:
packet- Packet to notify.
-
callPacketSent
Description copied from interface:SessionNotifies all listeners that a packet was just sent.- Specified by:
callPacketSentin interfaceSession- Parameters:
packet- Packet to notify.
-
getCompressionThreshold
public int getCompressionThreshold()Description copied from interface:SessionGets the compression packet length threshold for this session (-1 = disabled).- Specified by:
getCompressionThresholdin interfaceSession- Returns:
- This session's compression threshold.
-
setCompressionThreshold
public void setCompressionThreshold(int threshold, boolean validateDecompression) Description copied from interface:SessionSets the compression packet length threshold for this session (-1 = disabled).- Specified by:
setCompressionThresholdin interfaceSession- Parameters:
threshold- The new compression threshold.validateDecompression- whether to validate that the decompression fits within size checks.
-
enableEncryption
Description copied from interface:SessionEnables encryption for this session.- Specified by:
enableEncryptionin interfaceSession- Parameters:
encryption- the encryption to encrypt with
-
getConnectTimeout
public int getConnectTimeout()Description copied from interface:SessionGets the connect timeout for this session in seconds.- Specified by:
getConnectTimeoutin interfaceSession- Returns:
- The session's connect timeout.
-
setConnectTimeout
public void setConnectTimeout(int timeout) Description copied from interface:SessionSets the connect timeout for this session in seconds.- Specified by:
setConnectTimeoutin interfaceSession- Parameters:
timeout- Connect timeout to set.
-
getReadTimeout
public int getReadTimeout()Description copied from interface:SessionGets the read timeout for this session in seconds.- Specified by:
getReadTimeoutin interfaceSession- Returns:
- The session's read timeout.
-
setReadTimeout
public void setReadTimeout(int timeout) Description copied from interface:SessionSets the read timeout for this session in seconds.- Specified by:
setReadTimeoutin interfaceSession- Parameters:
timeout- Read timeout to set.
-
getWriteTimeout
public int getWriteTimeout()Description copied from interface:SessionGets the write timeout for this session in seconds.- Specified by:
getWriteTimeoutin interfaceSession- Returns:
- The session's write timeout.
-
setWriteTimeout
public void setWriteTimeout(int timeout) Description copied from interface:SessionSets the write timeout for this session in seconds.- Specified by:
setWriteTimeoutin interfaceSession- Parameters:
timeout- Write timeout to set.
-
isConnected
public boolean isConnected()Description copied from interface:SessionReturns true if the session is connected.- Specified by:
isConnectedin interfaceSession- Returns:
- True if the session is connected.
-
send
Description copied from interface:SessionSends a packet. -
disconnect
Description copied from interface:SessionDisconnects the session.- Specified by:
disconnectin interfaceSession- Parameters:
reason- Reason for disconnecting.
-
disconnect
Description copied from interface:SessionDisconnects the session.- Specified by:
disconnectin interfaceSession- Parameters:
reason- Reason for disconnecting.cause- Throwable responsible for disconnecting.
-
disconnect
public void disconnect(net.kyori.adventure.text.Component reason) Description copied from interface:SessionDisconnects the session.- Specified by:
disconnectin interfaceSession- Parameters:
reason- Reason for disconnecting.
-
disconnect
Description copied from interface:SessionDisconnects the session.- Specified by:
disconnectin interfaceSession- Parameters:
reason- Reason for disconnecting.cause- Throwable responsible for disconnecting.
-
getChannel
public io.netty.channel.Channel getChannel() -
refreshReadTimeoutHandler
protected void refreshReadTimeoutHandler() -
refreshReadTimeoutHandler
protected void refreshReadTimeoutHandler(io.netty.channel.Channel channel) -
refreshWriteTimeoutHandler
protected void refreshWriteTimeoutHandler() -
refreshWriteTimeoutHandler
protected void refreshWriteTimeoutHandler(io.netty.channel.Channel channel) -
channelActive
- Specified by:
channelActivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelActivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelInactive
- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
exceptionCaught
- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter
-
channelRead0
- Specified by:
channelRead0in classio.netty.channel.SimpleChannelInboundHandler<Packet>
-