• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 9
Eclipse IDE Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 8
1
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes! It now works! Thank you so much!
 
Christian Taylor
Greenhorn
Posts: 8
1
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome, glad it helped
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christian, good solution! Here's a cow for you

And Joshua, Welcome to CodeRanch!
 
reply
    Bookmark Topic Watch Topic
  • New Topic