0

I made a simple java client server program its work very well on my computer (localhost) but when I run the server on my computer and the client on friend computer I don't know how to get my full hostname that the client need when I go to system information get the hostname from their and run the client he cant find this hostname, what I supposed to do thank you for your help

Michael
  • 39
  • 7
  • Possible duplicate of [Recommended way to get hostname in Java](https://stackoverflow.com/questions/7348711/recommended-way-to-get-hostname-in-java) – azurefrog Oct 10 '17 at 12:54
  • Are your computer in the same local network (lan)? Do you have a static ip you can use to connect to the server? – Niklas P Oct 10 '17 at 13:00
  • No my computer not in the same local network but I will try with a computer in the same local network. How can I get static IP??? – Michael Oct 10 '17 at 13:10
  • Thank you very much but I need to connect my socket to a server in another local network you can help me??? – Michael Oct 10 '17 at 14:51

1 Answers1

0

Sounds like what you want is port forwarding.

  1. Login to your router by going to 192.168.1.1 on your web browser (if that doesn't work try 10.0.0.1)
  2. Type in your username and password for the router, they're usually on a sticker on the side of the router.
  3. Get your computer's local IP address by looking for your computer's name in the list of connected hosts on the router, or by following the instructions for your OS on https://kb.iu.edu/d/aapa
  4. Go to the port forwarding section on your router's config page and add a new rule that forwards traffic from the port you specified in your program (like 5000 or something like that) to your local IP address (something like 192.168.1.12).
  5. Get your public IP address from https://whatismyip.com
  6. Make your client program try to connect to your public IP on the port you chose
  7. Start your server on your computer that you port forwarded

You should then be able to tell your friend to start his client to connect to your server.

Steampunkery
  • 3,839
  • 2
  • 19
  • 28
  • Thank you very much, I think it will solve my problem but I cant login with the default IP address you gave me I have d D-LINK Router how can I find his IP? – Michael Oct 11 '17 at 07:47
  • Ahh, I see. The default IP on d-link routers is 192.168.0.1 – Steampunkery Oct 11 '17 at 12:21