Package one.pkg.tinyutils.network.nat
Class NettyProxy
java.lang.Object
one.pkg.tinyutils.network.nat.NettyProxy
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether the proxy server is currently running.voidstartTCPForward(int listenPort, String internalHost, int internalPort) Starts a TCP forwarding proxy.voidstartUDPForward(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.voidstop()Stops the operation of the proxy server.
-
Constructor Details
-
NettyProxy
public NettyProxy()
-
-
Method Details
-
startUDPForward
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
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.
-