1

I wrote a Simple Java Server-Client program. It works all fine when I use "localhost" as address in the Socket's constructor, but it fails when I specify my actual IP. Thus I think the problem is not in the Java-code. I've forwarded the Ports on my Router (a Speedport w921v from the German provider Telekom). On Windows 7 I've turned down every Firewall. I tried as well on Ubuntu 14. I use really the correct ip and not a local ip like 127. or 192.. When typing sudo netstat -tulpe I find this record which might belong to my program

tcp        0      0 *:10300                 *:*                     LISTEN      

10300 was the port I gave the Server with server = new ServerSocket(10300);

When I try to communicate with the port via telnet xx.xxx.xx.xxx 10300 I can't get no response but if I type telnet localhost 10300 I will get an answer.

I have really no clue why this problem occurs.

Sorry for the bad English ;)

Senf
  • 11
  • 2
  • If it's issue with your router you might on PowerUser or ServerFault. I have seen router that performed redirects only for connections coming from internet, but not from local network using to external address. You can ask a friend to check if he is able to connect from outside. Screenshot of what you have configured on router might be helpful. – NiematojakTomasz Jan 12 '15 at 18:10

1 Answers1

0

Use the ServerSocket() constructor and bind() to the particular IP and port you wish to use. Your machine may be multihoned and your Java server program may listen only to a particular network address, even if you didn't specify an actual address.

Danny Daglas
  • 1,501
  • 1
  • 9
  • 9
  • I've tried this one with the following lines: 'server = new ServerSocket(); server.bind(new InetSocketAddress(ip, port));' but the JVM is throwing this Exception: java.net.BindException: Cannot assign requested address – Senf Jan 12 '15 at 18:38
  • The `ip` you're using is an IP on your local machine? You can check with the `ifconfig -a` command on Linux/Mac, or the `ipconfig` command on Windows. – Danny Daglas Jan 12 '15 at 18:44