Package one.pkg.tinyutils.network.nat
Class NATProxy
java.lang.Object
one.pkg.tinyutils.network.nat.NATProxy
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the STUN mapping result for the default port.getSTUNMapping(int localPort) Establishes a STUN (Session Traversal Utilities for NAT) mapping by communicatingbooleanIndicates whether the NATProxy is currently running.voidstartTCPForward(int listenPort, String internalHost, int internalPort) Starts a TCP forwarding proxy that listens for incoming TCP connections on the specified port andvoidstartUDPForward(NATProxy.STUNMappingResult mappingResult, String internalHost, int internalPort) Starts forwarding UDP packets between an external STUN-mapped socket and an internal host/port.voidstop()Stops the NATProxy service and performs cleanup operations.
-
Constructor Details
-
NATProxy
public NATProxy() -
NATProxy
public NATProxy(int bufferSize)
-
-
Method Details
-
getSTUNMapping
Retrieves the STUN mapping result for the default port. The method determines the public IP address and public port- Throws:
Exception
-
getSTUNMapping
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
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.
-