Class NATProxy

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

public class NATProxy extends Object
  • Constructor Details

    • NATProxy

      public NATProxy()
    • NATProxy

      public NATProxy(int bufferSize)
  • Method Details

    • getSTUNMapping

      public NATProxy.STUNMappingResult getSTUNMapping() throws Exception
      Retrieves the STUN mapping result for the default port. The method determines the public IP address and public port
      Throws:
      Exception
    • getSTUNMapping

      public NATProxy.STUNMappingResult getSTUNMapping(int localPort) throws Exception
      Establishes a STUN (Session Traversal Utilities for NAT) mapping by communicating
      Throws:
      Exception
    • startUDPForward

      public void startUDPForward(NATProxy.STUNMappingResult mappingResult, String internalHost, int internalPort) throws Exception
      Starts forwarding UDP packets between an external STUN-mapped socket and an internal host/port. This method spawns a new thread for handling the UDP packet forwarding process.
      Parameters:
      mappingResult - The result of the STUN mapping, which contains the external socket to use for forwarding.
      internalHost - The hostname or IP address of the internal destination to which packets are forwarded.
      internalPort - The port number of the internal destination to which packets are forwarded.
      Throws:
      Exception - If an error occurs during the setup or execution of the UDP forwarding process.
      IllegalStateException - If the proxy is already running.
    • startTCPForward

      public void startTCPForward(int listenPort, String internalHost, int internalPort) throws Exception
      Starts a TCP forwarding proxy that listens for incoming TCP connections on the specified port and
      Throws:
      Exception
    • stop

      public void stop()
      Stops the NATProxy service and performs cleanup operations.

      This method halts all ongoing processes of the NATProxy, including shutting down sockets used for UDP and TCP communication

    • isRunning

      public boolean isRunning()
      Indicates whether the NATProxy is currently running.
      Returns:
      true if the NATProxy is running, false otherwise.