Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java UPnP IGD Ports

807580May 16 2010 — edited May 17 2010
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());
      this.start();    //Listening method on a new Thread
    }
  }catch(IOException ex){
    ex.printStackTrace();
  }
}
Edited by: Cap_Snake8 on May 16, 2010 3:06 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 13 2010
Added on May 16 2010
0 comments
273 views