简体   繁体   中英

Java Connect Over A Socket Using Public IP Address

I'm basically trying to connect to other computer. Everything works as I want once I use "localhost" as the IP address. If I try to put in my public IP, my client cannot find the server running although it is. If I switch it to "localhost" it works again.

I'm using a router or a modem or how do you call these things to split internet for 4 people + wireless. I have my port forwarded, but I still can't get it to work. What are the problems I might be encountering? I don't think this is the problem with the code since everything works properly with "localhost", unless I need to do something extra when switching to public IP.

I also tried to disable firewall and it still didn't work. When I checked what is my IP address it is said that my IP is static, but I don't see the difference.

Any thoughts/ideas are much appreciated.

There are two possible problems I can think of:

  1. You didn't forward your ports correctly, or there's some other problem with your router configuration. In that case, your question is better asked on Superuser .
  2. Your server is listening only on your loopback interface. Make sure in your server code you have it set to listen on 0.0.0.0, or whatever your library/OS equivalent is.

I have found my problem. I was doing everything correctly. And everything works correctly. The problem is that my router can't connect to itself using my static(external/public) IP. Other people can connect to my external/public IP properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM