• Post Reply Bookmark Topic Watch Topic
  • New Topic

Want to connect to computer over internet. Getting exception- Connection refused:connect

 
Harish Moolchandani
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create a simple chat program which can work through internet not only in local network. I started from basics and created two simple client and server program which on connecting shares one message. The java program works fine when testing on local network but when testing it through internet it gives exception "Connection refused: connect".

I'm testing on one PC (although I've tried it on two computers, but it didn't worked).
Server programs starts at port 5000. Client programs connects with Server by providing dynamic internet IP of server. Client also knows the port number.

Server Program:


Client Program:


What I've tried yet:
Tried disabling firewall and avast antivirus.
Done port forwarding into my router.
Tested telnet, it calls my modem home page, when called with dynamic IP.
Also, I tested it removing router and connecting directly to modem. But still getting exception.
Program is working in local network.

Please Help, I'm new to networking.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's do a check...
Change:

To:

See if there is any errors then. Remember to have the server running BEFORE you run the client...
John Price aka cc11rocks
 
Harish Moolchandani
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already mentioned that it is working in local network. So localhost or computer name or 192.168.X.X is working.
Also I haven't tested it outside my network i.e I tried running this program using 2 computers, but they are in the same network, hence their dynamic IP will be same. Although I port forwarded it, but no result. Should I try running client program outside my network?
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should easily run inside your network. Will take a look at it later today when I get home...
John Price aka cc11rocks
 
Harish Moolchandani
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried "netstat -a" to see where it is running and listening in my local network. And it was listening to 0.0.0.0:5000, I though it might be a problem and binded it with my local network address which is 192.168.0.102. And now it is listening to 192.168.0.102:5000.
But now the problem is, this is the local address. In Foreign Address, the "netstat -a" shows "HARISH:0", the name of the computer is OK but the port number is 0. What does this means?
 
Harish Moolchandani
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is solved.
Problem was not in my program, but in port forwarding, my modem is also a router and it was blocking incoming connection making them unable to reach to my router.
I took help from http://forum.pcwintech.com website's forum. Awesome website admins are wiling to help anytime. Anyone has networking related problem can refer to this site.
Here is my forum post link, if anyone has this issue.
Problem in Port Forwarding
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!