0

Im making a client/server app just for learning purposes, and i want my Client to connect the server (which is running in my pc) from another pc.

Right now im trying to use the server's pc public ip (which I got with whatsmyip.org) in the Client socket: Socket sock = new Socket(HOST, PORT); where host is the public ip of the server's pc.

When I was testing it with localhost and the client running in the same pc, the connection worked.

I already oppened the port im using in the Server pc and added firewall rules, including router's firewall. So any of my firewalls should be blocking the connection to the port im using.

I read in another question this (it was an example): "Your Server PC is in New York with an IP 192.168.1.121, that is behind a router with internal IP 192.168.1.1 and public IP 40.20.26.63. You will need to make sure that you go into the router and forward port 8084 (TCP) to internal address 192.168.1.121 (the internal Server PC)." How can I do that? I know the public IP and the internal IP of the server, but I dont know what IP I need to type in the Client Socket.

Thanks in advance.

ElChusky
  • 39
  • 6
  • *I dont know what IP I need to type in the Client Socket.* The **public** ip. – Elliott Frisch Feb 27 '21 at 23:53
  • But i have already done that and it gives me the exception java.net.ConnectException: Connection refused: connect – ElChusky Feb 28 '21 at 00:01
  • As you said you need to route the connection from the publicly exposed port to your server. There's probably some option in the router's configuration application (look for something about NAT or "port forwarding"). But this is beyond the scope of stackoverflow and probably more on-topic on [superuser](https://superuser.com). – Federico klez Culloca Feb 28 '21 at 00:08
  • Is Port Forwarding going into my router conf and oppening the ports there? if its that, i already did it and nothing – ElChusky Feb 28 '21 at 00:27
  • 1
    If the client is on your local network, use your 10.x.x.x ip. Especially, if you are behind a firewall, eg if you are on your company’s network, your public ip is meaningless. – Bohemian Feb 28 '21 at 01:53
  • Have you tried it using another network? So you can check whether the issue is with the firewall. Also, running the server before running the client might fixed it. There are some fixes which worth having a look here. https://stackoverflow.com/questions/6876266/java-net-connectexception-connection-refused – VihangaAW Feb 28 '21 at 05:51

0 Answers0