Is it possible to write code using pure Java to port-forward from your router. The PS3 and other programs do it. I would like to know how to do this in Java. What I mean is, without setting up your router, how would you set up port-forwarding so your program could become a server. I am sorry if this is really bad formatting of the question. I don't know how to phrase it. I just want to know how to do port forwarding so a program can be a server using pure Java code.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Port forwarding itself is simple enough; you open a java.net.ServerSocket on the "from" port to listen on, and every byte you receive there, you write to a java.net.Socket opened to wherever the data is supposed to go; you'll need to send return data back via the opposite path. You'll either need to dedicate a couple of threads, or use NIO java.nio.channels.Selectors .
But what do you mean exactly, "so a program can be a server?" That's the part I don't understand.
Port forwarding can only route traffic through open ports; it can't make a path through a firewall if there is no path available to use. Basically all you can do with port forwarding is run a server that listens on port A on machine X, and a client on machine Y that connects to port B on either machine X or Y. The port forwarding connects that client to that server. But either port A or port B must be open on any firewall protecting machine X, or this can't be made to work, and the precise technique for doing it depends on which of those ports is available.
What you are looking for is called Universal Plug and Play. It's a protocol that allows a networked device to control other network devices. In this case, your PS3 tells your router what routes it needs. Sorry, but I haven't used it myself. There seems to be at least one project that provides an API.