0

I just made a little chat programm with a server and a client in java. The client needs to connect to the server with the ip of the server. All my testing I did with the localhost (127.0.0.1) and everything went fine, but when I tested it later on with a friend of mine, I had to notice that if I put my ip address (I run the server, he runs the client) that it doesn't work. Is there a way to set up a private little server on my pc to run my server on, or maybe another way to get it working?

EDIT:

Just found a tool called "Apache" to set up your own server, could that might be helpful?

EDIT: When I say it doesnt work I mean I get an IOException, because this fails:

public void connectToServer() throws IOException{

    showMessage("Attemption to connect...");
    connection = new Socket(InetAddress.getByName(serverIP), 6789);
    showMessage("\nConnected to: " + connection.getInetAddress().getHostName());
}
Aaron Priesterroth
  • 307
  • 2
  • 4
  • 17
  • When you say it doesn't work what do you mean? Do you get an error? If yes then please add the stacktrace. Does your friend uses your public IP address correctly? You know that 127.0.0.1 is not your actual IP, right? – c.s. Aug 15 '13 at 14:05
  • Make sure you start your server with 0.0.0.0 and not 127.0.0.1 – KevinDTimm Aug 15 '13 at 14:45
  • I'm starting with an input dialog asking for the ip to connect with :) – Aaron Priesterroth Aug 15 '13 at 18:21

2 Answers2

1

There is a whole host of things that you need to look at before your application will work.

  • Firewalls on both ends (and anti-virus applications) need to allow the programs to communicate
  • Your ISP needs to allow messages to be sent via your designated ports
  • Your router (and the clients) need to not-filter these messages.

As a start, see if you can ping each others IP addresses and take it from there.

Husman
  • 6,819
  • 9
  • 29
  • 47
  • To be honest I think the whole message from here to there thing is fine, Firewall on both end was turned off while we were testing, anti-virus aswell. I googled a little bit before and I found that once the client asks to connect with my rounter via my ip, my rounter doesnt know what to do with it, since its on a server, its only a LAN. Thtas why I asked of there's a way to set up such a server. – Aaron Priesterroth Aug 15 '13 at 13:31
1

I recommend you first try and disable your firewall. If you are using windows, here is the instruction for turning off windows firewall: Turn Windows Firewall on or off

If you are testing with someone outside of your local network, you may need to setup NAT on the router of the person hosting the server. You can access the router by typing in it's local IP address in the web browser. This is usually something like 192.168.1.1 or 192.168.1.254 but it will depend on the model and network setup.

Once you have connected you should find an option (usually under advanced) for "NAT" or "Port Forwarding". I suggest you do a google search with the router model and how to setup port forwarding.

You also need to be aware that some ISPs will block certain ports. I suggest testing on a common port such as port 80 (HTTP) since it's unlikely an ISP will block this (be aware that you will need to disable Skype or any local web servers to test this)

LondonAppDev
  • 8,501
  • 8
  • 60
  • 87