Class RconClient

java.lang.Object
io.github.theword.queqiao.core.rcon.RconClient

public class RconClient extends Object
单条 RCON 连接的生命周期与命令串行化边界。

RCON 使用请求—响应协议,不能让多个线程并发读写同一个 socket。命令、连接和关闭 由同一个对象监视器串行化;关闭等待当前命令完成,关闭完成后的命令得到明确的断开错误。

  • Constructor Summary

    Constructors
    Constructor
    Description
    RconClient(org.slf4j.Logger logger, int port, String password)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    尝试连接 RCON;连接已存在时保持幂等。
    boolean
     
    在检查连接状态与发送命令的整个期间持有监视器,避免 stop/connect 与命令交错。
    void
    关闭连接;与命令和连接建立串行执行,重复调用安全。

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RconClient

      public RconClient(org.slf4j.Logger logger, int port, String password)
  • Method Details

    • connect

      public void connect()
      尝试连接 RCON;连接已存在时保持幂等。
    • sendCommand

      public String sendCommand(String command) throws RconException
      在检查连接状态与发送命令的整个期间持有监视器,避免 stop/connect 与命令交错。
      Throws:
      RconException
    • stop

      public void stop()
      关闭连接;与命令和连接建立串行执行,重复调用安全。
    • isConnected

      public boolean isConnected()