• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.net.ConnectException: Connection refused: no further information  RSS feed

 
Joshua Minter
Greenhorn
Posts: 9
Chrome Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I am completely new to JavaRanch? (or is it CodeRanch? or Big Moose Saloon?) and I am also new to NIO.

I am programming this card playing game and I decided to use NIO for the sole reason that I didn't want hundreds of threads.
I ended up making it single threaded (using selectNow, is this a bad thing) for 2 reasons:
- multithreading is a pain
- I'm using LWJGL which most of the methods only work on the main thread

But I am getting this error when I run the program twice, one hosting and the other one connecting to my IP:


My code is hosted on Github at https://github.com/matanui159/Card-Player/tree/no-engine.

Some more information:
- I have googled it and apparently it happens either when the port Isn't used or the "backlog queue" is full, which happens when alot of clients are connecting, but only one client is connecting and both the client and the server share a common port (at NetConstants.PORT = 22737)
- It still works when I use the loopback address (127.0.0.1)
- when I try to connect from another computer (on LAN still) I get a timeout error instead

Can someone please help me. If there is any information I forgot or I'm breaking one of the rules, let me know, and I will fix.
Thanks in advance.

 
Joshua Minter
Greenhorn
Posts: 9
Chrome Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, there hasn't been any replies, and I know I kind of just gave you a bunch of code and told you to fix it for me, so I did a bit of testing.
This code here does not work:


It gives the error:


Which narrows it down to the two classes:
com.redmintie.game.util.net.Client and
com.redmintie.game.util.net.Server

I will see what else I can find and reply to this topic with anything I find.
Thanks in advance.
 
Joshua Minter
Greenhorn
Posts: 9
Chrome Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to simplify it down more:


But still:


Isn't that code as simple as it gets? I have no idea what is going wrong. Can someone please help me?
Thanks in advance.
 
Christian Taylor
Greenhorn
Posts: 8
1
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are binding the server socket to the loopback address:



So therefore it works on loopback, but not on any other address your system has. If you look at the javadoc for java.net.InetSocketAddress you'll see it has another constructor that takes only a port and binds to the wildcard address, which means any address your system has. Give that a try.
 
Joshua Minter
Greenhorn
Posts: 9
Chrome Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes! It now works! Thank you so much!
 
Christian Taylor
Greenhorn
Posts: 8
1
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome, glad it helped
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christian, good solution! Here's a cow for you

And Joshua, Welcome to CodeRanch!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!