0
Hello, I am trying to do port forwarding on my router automatically. For this, I am using the Cling 2.1.2 in Java.
My code:
package teste_cling;
import java.net.ServerSocket;
import java.net.Socket;
import org.fourthline.cling.UpnpService;
import org.fourthline.cling.UpnpServiceImpl;
import org.fourthline.cling.support.igd.PortMappingListener;
import org.fourthline.cling.support.model.PortMapping;
public class RedirecionamentoPortas {
private static final int PORTA = 3322;
public static void main(String[] args) {
PortMapping mapeamento = new PortMapping(PORTA, "192.168.0.3", PortMapping.Protocol.TCP, "Redirecionamento de Porta TCP");
UpnpService servicoUPnP = new UpnpServiceImpl(new PortMappingListener(mapeamento));
servicoUPnP.getControlPoint().search();
try(ServerSocket servidor = new ServerSocket(PORTA);
Socket cliente = servidor.accept()) {
System.out.println("\nO cliente " + cliente.getInetAddress().getHostAddress() + " se conectou.");
}
catch(Exception excecao) {
System.err.println(excecao.getMessage());
}
servicoUPnP.shutdown();
}
}
I’m basing myself on this example cling’s own.
The code compiles and executes, but I can’t connect remotely (on another network) with the server on the specified port.
To test whether the door is open or closed, I’m using this website.
I didn’t set the redirect on my router, but Upnp is enabled:
Does my computer need to be wired to the router for Cling’s remote configuration to run? Or is it the same thing to be connected by wi-fi? I tested both ways and it didn’t work.
Exit from the program:
abr 21, 2021 1:15:52 AM org.fourthline.cling.UpnpServiceImpl <init>
INFORMAÇÕES: >>> Starting UPnP service...
abr 21, 2021 1:15:52 AM org.fourthline.cling.UpnpServiceImpl <init>
INFORMAÇÕES: Using configuration: org.fourthline.cling.DefaultUpnpServiceConfiguration
abr 21, 2021 1:15:52 AM org.fourthline.cling.transport.RouterImpl <init>
INFORMAÇÕES: Creating Router: org.fourthline.cling.transport.RouterImpl
abr 21, 2021 1:15:53 AM org.fourthline.cling.transport.impl.MulticastReceiverImpl init
INFORMAÇÕES: Creating wildcard socket (for receiving multicast datagrams) on port: 1900
abr 21, 2021 1:15:53 AM org.fourthline.cling.transport.impl.MulticastReceiverImpl init
INFORMAÇÕES: Joining multicast group: /239.255.255.250:1900 on network interface: Qualcomm Atheros QCA9377 Wireless Network Adapter
abr 21, 2021 1:15:53 AM org.fourthline.cling.transport.impl.MulticastReceiverImpl init
INFORMAÇÕES: Creating wildcard socket (for receiving multicast datagrams) on port: 1900
abr 21, 2021 1:15:53 AM org.fourthline.cling.transport.impl.MulticastReceiverImpl init
INFORMAÇÕES: Joining multicast group: /239.255.255.250:1900 on network interface: VirtualBox Host-Only Ethernet Adapter
abr 21, 2021 1:16:07 AM org.fourthline.cling.transport.impl.StreamServerImpl init
INFORMAÇÕES: Created server (for receiving TCP streams) on: /192.168.0.3:58863
abr 21, 2021 1:16:07 AM org.fourthline.cling.transport.impl.DatagramIOImpl init
INFORMAÇÕES: Creating bound socket (for datagram input/output) on: /192.168.0.3
abr 21, 2021 1:16:07 AM org.fourthline.cling.transport.impl.StreamServerImpl init
INFORMAÇÕES: Created server (for receiving TCP streams) on: /192.168.56.1:58866
abr 21, 2021 1:16:07 AM org.fourthline.cling.transport.impl.DatagramIOImpl init
INFORMAÇÕES: Creating bound socket (for datagram input/output) on: /192.168.56.1
abr 21, 2021 1:16:07 AM org.fourthline.cling.UpnpServiceImpl <init>
INFORMAÇÕES: <<< UPnP service started successfully
abr 21, 2021 1:16:13 AM org.fourthline.cling.protocol.RetrieveRemoteDescriptors describe
ADVERTÊNCIA: Could not hydrate device or its services from descriptor: (RemoteDevice) Identity: (RemoteDeviceIdentity) UDN: uuid:KNKODM2K5000000000000000000000000000075452, Descriptor: http://192.168.0.10:9080, Root: true
abr 21, 2021 1:16:13 AM org.fourthline.cling.protocol.RetrieveRemoteDescriptors describe
ADVERTÊNCIA: Cause was: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; O conteúdo não é permitido no prólogo.
abr 21, 2021 1:16:41 AM org.fourthline.cling.UpnpServiceImpl$1 run
INFORMAÇÕES: >>> Shutting down UPnP service...
Any tips? Thank you.