• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Port forwarding from inside Java?

 
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Thanks,
John Price
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I don't open a port on my server, I haven't been able to successfully use a server program as a server (the router blocks it I assume). Your "Selectors" link leads to a 404 error page.

John Price
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that should be java.nio.channels.Selector.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fixed my links, sorry.

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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic