Can't connect to my server socket using external IP

Hi I'm very new to Java programming, and I'm learning all the core things I need to understand so that I can make a simple networked game using a command-line server and applet clients. I tried the networking tutorial and it worked perfectly on my machine.

However, it only works if I supply the client with my INTERNAL IP. When I give it my EXTERNAL IP it cannot connect to the server socket. The error thrown is a IOException.

The code:

import java.io.*;

import java.net.*;

publicclass KnockKnockClient{

publicstaticvoid main(String[] args)throws IOException{

Socket kkSocket =null;

PrintWriter out =null;

BufferedReader in =null;

try{

kkSocket =new Socket("192.168.2.3", 4444);

out =new PrintWriter(kkSocket.getOutputStream(),true);

in =new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));

}catch (UnknownHostException e){

System.err.println("Don't know about host.");

System.exit(1);

}catch (IOException e){

System.err.println("Couldn't get I/O for the connection.");

System.exit(1);

}

BufferedReader stdIn =new BufferedReader(new InputStreamReader(System.in));

String fromServer;

String fromUser;

while ((fromServer = in.readLine()) !=null){

System.out.println("Server: " + fromServer);

if (fromServer.equals("Bye."))

break;

fromUser = stdIn.readLine();

if (fromUser !=null){

System.out.println("Client: " + fromUser);

out.println(fromUser);

}

}

out.close();

in.close();

stdIn.close();

kkSocket.close();

}

}

The code works fine with my internal IP (192.168.2.3) but not my external IP (86.3.51.171). Any ideas about how to fix it?

[3231 byte] By [robinjama] at [2007-10-3 9:32:31]
# 1

Not quite sure I understand. Do you use the external IP with clients

from the external network or with clients from the internal network?

But regardless, I assume your Java code is correct since it works

on the internal network. Try this command:

telnet 192.168.2.3 4444

from the internal network. I expect it to show "Server: ...", whatever the

server sends. If this works, it means we can indeed use telnet to

test connectivity. Now do:

telnet 86.3.51.171 4444

from the machine that gives you problems. If this does not work

(connection lost or something like this), it means your Java code is OK

and you need to do some configuration at your router.

If this works, which I doubt, I am on the wrong track.

baftosa at 2007-7-15 4:47:33 > top of Java-index,Archived Forums,Socket Programming...