22declare(strict_types=1);
31 private ?
string $serviceURL =
null;
33 public function __construct(
38 if(!Internet::$online){
39 throw new \RuntimeException(
"Server is offline");
42 $this->logger = new \PrefixedLogger($logger,
"UPnP Port Forwarder");
46 $this->logger->info(
"Attempting to portforward...");
51 $this->logger->info(
"Forwarded $this->ip:$this->port to external port $this->port");
53 $this->logger->error(
"UPnP portforward failed: " . $e->getMessage());
57 public function setName(
string $name) : void{
61 public function tick() : void{
65 public function shutdown() : void{
66 if($this->serviceURL === null){
70 UPnP::removePortForward($this->serviceURL, $this->port);
static portForward(string $serviceURL, string $internalIP, int $internalPort, int $externalPort)