Class NettyProxy

java.lang.Object
one.pkg.tinyutils.network.nat.NettyProxy

public class NettyProxy extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks whether the proxy server is currently running.
    void
    startTCPForward(int listenPort, String internalHost, int internalPort)
    Starts a TCP forwarding proxy.
    void
    startUDPForward(int listenPort, String internalHost, int internalPort)
    Starts a UDP forwarding proxy that listens on the specified port, forwards incoming UDP packets to the given internal host and port, and returns the responses to the sender.
    void
    Stops the operation of the proxy server.

    Methods inherited from class java.lang.Object

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

    • NettyProxy

      public NettyProxy()
  • Method Details

    • startUDPForward

      public void startUDPForward(int listenPort, String internalHost, int internalPort) throws Exception
      Starts a UDP forwarding proxy that listens on the specified port, forwards incoming UDP packets to the given internal host and port, and returns the responses to the sender.
      Parameters:
      listenPort - The port on which the proxy listens for incoming UDP packets.
      internalHost - The host to which incoming UDP packets will be forwarded.
      internalPort - The port on the internal host to which incoming UDP packets will be forwarded.
      Throws:
      Exception - If an error occurs while starting the UDP forwarding proxy or if the proxy is already running.
    • startTCPForward

      public void startTCPForward(int listenPort, String internalHost, int internalPort) throws Exception
      Starts a TCP forwarding proxy. Listens for incoming connections on the specified port and forwards the traffic to an internal host and port. This method initializes the necessary Netty components and sets up the channel pipeline for handling TCP traffic.
      Parameters:
      listenPort - The port on which the proxy will listen for incoming connections.
      internalHost - The hostname or IP address of the internal server to which connections will be forwarded.
      internalPort - The port on the internal host to which connections will be forwarded.
      Throws:
      Exception - If an error occurs during the initialization or if the proxy is already running.
    • stop

      public void stop()
      Stops the operation of the proxy server.

      This method sets the running state to false, closes the server channel if it is active, and gracefully shuts down the boss and worker thread groups used by the server.

    • isRunning

      public boolean isRunning()
      Checks whether the proxy server is currently running.
      Returns:
      true if the proxy server is running, false otherwise.