0

I tried to make a chat program with java. i succeed when i use the ip of 127.0.0.1 to connect.

Socket socket = new Socket("127.0.0.1",5005);

it all worked great on my computer and the program even worked when i try to connect between my comupter and my leptop which uses the same router. (i did it by using the local ip.) Then i wanted to connect computers which uses other routers by using the external ip. so i read on web and i understand that i need to forwad my port through my router. i have a Siemens ADSL Sl2-141 router. i forwad the port 5005, and my chat program still doesn't work. i get Connection Refused error over and over. did i missed somthing? Siemens port forwading

2
  • double check Internal Host IP-address. Did you try both your laptop and your desktop computer as target?. Do you use any further (software)-Firewalls?
    – yankee
    Feb 11, 2013 at 17:03
  • NOTE: Although this question has been migrated I don't think it is clear if this is a network configuration issue or a code issue (listener/connection going through correct IP addresses). Until we get more information it may be a case of hasty moderation.
    – Grambot
    Feb 11, 2013 at 19:22

2 Answers 2

1

First, it seems you're configuring your code to listen on the localhost only and not external address. Use a socket connection like this instead: (as per this guide)

EDIT (Changed as per comment discussion below):

Socket socket = new Socket("PUBLIC_IP_ADDR",5005);

Where PUBLIC_IP_ADDR is your internet facing address that you can locate here

If you still can't get a connection verify the program is available and listening...

Guide to checking your port

1) If you haven't already, go through this guide and confirm you've done all the steps.

2) Use this tool to confirm your port is actually open.

If #2 fails then your port is not actually open. Does the PC that accepts the connection actively listen on 5005?

Windows:

Start -> Run -> cmd
  netstat -an | find /i "5005"

Linux:

(From terminal)
  netstat -l | grep 5005

If that doesn't have "LISTENING" listed beside it then your application is not listening for connections. But I don't suspect this to be the problem since you can do it on localhost.

If that fails then confirm your OS firewall is open.

That's about all I can think of right now

5
  • the code above is for the client file. in the server i used the code you gave. the tool you gave give me positive answer: Success: I can see your service on 77.126.189.65 on port (5005) Your ISP is not blocking port 5005 i also tried through the cmd to check. this was part of the answer: TCP 0.0.0.0:5005 0.0.0.0.0 LISTENING the 0.0.0.0.0 mybe mean somthing?
    – עומר שלף
    Feb 11, 2013 at 17:39
  • 0.0.0.0 Simply means its listening on all IPs (I believe). If you have the client file attempting to access a service on port 5005 of 127.0.0.1 it will attempt to find your server on the same computer you're connecting from. Change that to your public IP address. I'll update the answer with details.
    – Grambot
    Feb 11, 2013 at 17:42
  • Sorry, do you mean you were able to connect? Or are you still unable to? EDIT: Also, since you are opening your service publicly I would suggest hiding the IP for the meantime in case anonymous people stumble on this page and start attempting to connect to you.
    – Grambot
    Feb 11, 2013 at 18:05
  • i able to connect when i use 127.0.0.1. i cannot connect when i use my external ip for connection
    – עומר שלף
    Feb 11, 2013 at 18:32
  • Can you edit your question to include the code you set up the socket listener with as well?
    – Grambot
    Feb 11, 2013 at 18:35
0

What @Brian said. Your internal address is probably wrong, if the program isn't running. Try replacing "127.0.0.1" with the internal ("10.whatever") address and then still run it from the same computer. If that works, only then should you try it from another computer. If it's blocked from another computer on the same subnet, then it's likely you have a software firewall ("Windows Defender" or some such) that's blocking external connections.

The problem of scope still remains: if you need help configuring your router, Google and then superuser.com are the places to ask. If you need help with programming, that's what this site is for.

1
  • i did succeed run the program by using internal ip(10.0.0.3 instead of 127.0.0.1). now im trying run the program by external ip
    – עומר שלף
    Feb 11, 2013 at 17:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .