tcp chat program, I don't like that i have to set up my router to forward ports

i’m trying to right a tcp chat program i have it set up so that you can choos to be either the server or the client
the server is set up like this:

ServerSocket srvr = new ServerSocket(port);
Socket skt = srvr.accept();

and the client is set up like this:

Socket skt = new Socket(ipAdress,port);

It works running both on one computer using port 12345 and ip “localhost”, and it works over internet using port 12345 and my public ip. But for it to work over the internet i had to set up my router to forward port 12345 to my computer running the server.
how do i make it so that the program opens up a user defined port and forwards it to the server computer, so that users of the program only have to know the public ip of the server and the port. I don’t know if that’s how its supposed to work but that was what i was thinking. Thanks.

What you want is called “UPnP”. It’s a technology that most routers implement that allows applications to open ports and forward traffic automatically.

Google should be able to turn up Java implementations.

In regards to UPnP, I found this: http://www.sbbi.net/site/upnp/docs/natmappings.html

You can use it to configure your router to redirect traffic. Does anyone have experience using UPnP? It sounds really cool, but I wonder (a) how well it works and (b) how many routers actually support it?

If anyone is interested, I write a small test program to see how well that works (you folks would have to run it though)?