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.