Class BufferedConnection

java.lang.Object
alexiil.mc.lib.net.ActiveConnection
alexiil.mc.lib.net.BufferedConnection
Direct Known Subclasses:
ActiveMinecraftConnection

public abstract class BufferedConnection extends ActiveConnection
An ActiveConnection which buffers packets until one of the following:
  1. flushQueue() is called
  2. maximumPacketSize() is reached
  3. .
  4. tick() is called, which also calls sendTickPacket() beforehand.
  • Field Details

  • Constructor Details

    • BufferedConnection

      public BufferedConnection(ParentNetId rootId, int defaultDropDelay)
  • Method Details

    • setMaxBandwidth

      public void setMaxBandwidth(int to)
    • sendPacket

      protected final void sendPacket(NetByteBuf data, int packetId, @Nullable NetIdBase netId, int priority)
      Specified by:
      sendPacket in class ActiveConnection
      packetId - The packet ID that has been written out to the first int of the given buffer.
      netId - The NetIdBase that is being written out. Will be null if the packet ID is one of the internal packets.
      priority - The priority for the packet. Will be either 0 or a negative number.
    • maximumPacketSize

      protected int maximumPacketSize()
      Returns:
      The maximum packet size that a single output packet can be. Used to try to keep the data sent to sendRawData0(NetByteBuf) below this value when combining data into packets.
    • tick

      public void tick()
      Ticks this connection, flushing all queued data that needs to be sent immediately.
    • sendTickPacket

      protected void sendTickPacket()
      Optional method for subclasses to send additional packet before the queue is flushed.
    • flushQueue

      public void flushQueue()
      Description copied from class: ActiveConnection
      Flushes any packet queues, if present. In LNS itself this doesn't do anything unless this is a BufferedConnection
      Overrides:
      flushQueue in class ActiveConnection
    • hasPackets

      protected final boolean hasPackets()
    • onReceiveRawData

      public void onReceiveRawData(NetByteBuf data) throws InvalidInputDataException
      Overrides:
      onReceiveRawData in class ActiveConnection
      Throws:
      InvalidInputDataException
    • sendRawData0

      protected abstract void sendRawData0(NetByteBuf data)
      Sends some raw data. It might contain multiple packets, half packets, or even less. Either way the implementation should just directly send the data on to the other side, and ensure it arrives in-order.