模块 mxlib.api

类 RemoteConnection

  • 直接已知子类:
    AuthenticationRemoteConnection

    public class RemoteConnection
    extends Event
    RemoteConnection. As Server Or Client.

    The reason we break the specification ourselves is because we want each Remote Server/Connection to have its own listening system instead of the global listening system.

    RemoteConnection will not provide static handlers field, as that may lead to the disclosure of security information, which is not what we want.

    • 构造器详细资料

      • RemoteConnection

        public RemoteConnection​(SocketChannel socket)
        Create a new connection boxing.
        参数:
        socket - The socket channel. Can be ClientSocket or Server Accept Socket.
    • 方法详细资料

      • getStatus

        public RemoteConnection.Status getStatus()
        Get the current status for this connection
        返回:
        Current for this connection
      • sendPacket

        public void sendPacket​(short type,
                               @NotNull
                               @org.jetbrains.annotations.NotNull byte[] data)
                        throws IOException
        Send packet to remote
        参数:
        type - The packet id.
        data - The data send
        抛出:
        IOException - IOException
      • getBuffer

        public ByteBuffer getBuffer()
        Get the data buffer. You need to read the data sent from here.
        返回:
        remote data
      • sendPacket

        public void sendPacket​(short type,
                               @NotNull
                               @org.jetbrains.annotations.NotNull byte[] data,
                               int off,
                               int len)
                        throws IOException
        Send packet to remote. It used ByteBuffer.wrap(byte[], int, int)
        参数:
        type - The packet id
        data - The data send
        off - The data offset
        len - The data length
        抛出:
        IOException
      • sendPacket

        public void sendPacket​(short type,
                               @NotNull
                               @NotNull ByteBuffer send)
                        throws IOException
        Send a packet to remote
        参数:
        type - The packet id.
        send - The data
        抛出:
        IOException - IOException.
      • badPacket

        public void badPacket()
                       throws IOException
        Send "Bad packet" packet and disconnect this connection.

        0x1, "Bad Packet.".getBytes(StandardCharsets.UTF_8)

        抛出:
        IOException - If cannot send packet/cannot disconnect.
      • disconnect

        public void disconnect​(String message)
                        throws IOException
        Send packet "0x1, <message>" and call disconnect()
        参数:
        message - The disconnect message will send.
        抛出:
        IOException - IOException
      • disconnect

        public void disconnect()
                        throws IOException
        Close this connection
        抛出:
        IOException - when cannot closed this connection.