Skip to main content

Java UPnP IGD Ports

1 reply [Last post]
cap_snake8
Offline
Joined: 2010-05-16

I've opened a TCP port using upnplib libraries, and the port is actually opened, but when i try connecting to a SocketServer listening to that port, i get no response.

upnplib: http://www.sbbi.net/site/upnp/index.html


public Test() {
int port=54780;
int discoveryTimeout = 2000;
try {
//Discovery of the router
InternetGatewayDevice[] IGDs = InternetGatewayDevice.getDevices(discoveryTimeout);
if (IGDs != null) {
InternetGatewayDevice testIGD = IGDs[0];
//Internal Address
local=InetAddress.getLocalHost().getHostAddress();
//Open a new TCP port called UPnP Test
testIGD.addPortMapping("UPnP Test",null,port,port,local,0,"TCP");
}
} catch (Exception ex) {
ex.printStackTrace();
}
try {
System.out.println("listening on port:"+port);
server=new ServerSocket(port); //Server listening on opened port
while(true){
//Accept the client and create comunication streams
client=server.accept();
System.out.println("Client found:"+client.getInetAddress());
in=new BufferedReader(new InputStreamReader(client.getInputStream()));
out=new PrintStream(client.getOutputStream());
//Listening method on a new Thread
this.start();
}
}catch(IOException ex){
ex.printStackTrace();
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
perjarles
Offline
Joined: 2010-12-04

Hi
Did you find a solution to this?

I tried the same yesterday without success

Best regards
Per-Jarle