• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Connection Problems with a Multi-user Server Application  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have been stuck on this problem for about 3 days now, and it is really stressing me out. The application I am creating is sort of a sign-in/sign-out application that uses a central server to store all of the data in a database. It worked perfectly fine when only one client was connected to the server, but when I tried to make the server allow for multiple connections, it kept giving me this error whenever a client would connect: java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine. I just do not understand why it is all of a sudden giving me this error when I tried to make the server accept multiple connections, but when I only had it accepting one connection it never gave me this error. I can provide any of the code if that would help with figuring out this issue.
 
Saloon Keeper
Posts: 2270
290
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your environment IPv4, IPv6, or dual-stack?

Can you show the code on the server side (or maybe something simpler which exhibits the same problem)?

Can you also post the stack trace for the exception?
 
Ron McLeod
Saloon Keeper
Posts: 2270
290
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to the Ranch
 
Logan Jones
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:Is your environment IPv4, IPv6, or dual-stack?

Can you show the code on the server side (or maybe something simpler which exhibits the same problem)?

Can you also post the stack trace for the exception?



Thank you!    Sorry, I'm brand new to networking and network programming, but I looked up my error before making this thread and I'm pretty sure I set the environment to a IPv4. So when starting this project, I'm using the class ConnectionHandler to handle all things server related. The class allows the application to act as a client or a server depending on what constructor you use.

Here's the original code that allows a one-to-one connection (before trying to allow for multiple connections at one time):
 
Logan Jones
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the code after trying to allow the server to have multiple connections at one time:


So this class actually isn't one that I created myself. I found it when I was doing some research on Servers/Clients that used GUI in them, and it was so perfect for what I wanted to do, that I used it and changed it up to fit my needs.
 
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

giving me this error  


Can you copy the full text of the error messages and paste it here?

Make sure all catch blocks have calls to the printStackTrace() method to show what and where.
 
Logan Jones
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

giving me this error  


Can you copy the full text of the error messages and paste it here?

Make sure all catch blocks have calls to the printStackTrace() method to show what and where.



Here's the error it is giving me:

java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at application.MainController$ConnectionHandler.run(MainController.java:376)
 
Norm Radder
Rancher
Posts: 3353
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

at application.MainController$ConnectionHandler.run(MainController.java:376)


What line in the posted code is line 376 referenced in the error message?


Address is invalid on local machine, or port is not valid on remote machine  


What is the value of the port being passed to the Socket constructor?
 
Logan Jones
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

at application.MainController$ConnectionHandler.run(MainController.java:376)


What line in the posted code is line 376 referenced in the error message?


Address is invalid on local machine, or port is not valid on remote machine  


What is the value of the port being passed to the Socket constructor?



This is line 376:


The port value I am using is 12345. I have checked and that port is not being occupied by any other process
 
Norm Radder
Rancher
Posts: 3353
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I search for the the statement you entered, There isn't a line that matches "new Socket(remoteHost, port);"
There are two lines that have this: new Socket(remoteHost,port);     <<< No space after ,
What is the line number in where the exception happened?

What is the value of remoteHost?
 
Ron McLeod
Saloon Keeper
Posts: 2270
290
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is that line for?  The client socket is returned by listener.accept()

Also, remoteHost is never initialized, so it will have a value of null, which is understood to mean the IP address of the loopback interface: 127.0.0.1;
 
Logan Jones
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:When I search for the the statement you entered, There isn't a line that matches "new Socket(remoteHost, port);"
There are two lines that have this: new Socket(remoteHost,port);     <<< No space after ,
What is the line number in where the exception happened?

What is the value of remoteHost?



Here's the other bit of code that is in the MainController class:



Sorry for the jumbled code and all the commented out lines. I have been playing around with things to try to fix this.

So the way the application is set up, that line of code should only be used on the client side, unless I'm missing something? The value of remoteHost should be the ip address that the client is trying to connect to. Could it be that the server is trying to connect to the client in some way and that's why it is giving me that error?
 
Logan Jones
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:What is that line for?  The client socket is returned by listener.accept()

Also, remoteHost is never initialized, so it will have a value of null, which is understood to mean the IP address of the loopback interface: 127.0.0.1;



From my understanding of the page I found the original ConnectionHandler class from, that line of code is used when the application is acting as a client. I don't know why the server would be trying to use it
 
Norm Radder
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The value of remoteHost should be ...


Ok, but what was its value when the exception happened?

The print out (posted messages) should show the values.  What did postMessage() output?
 
Logan Jones
Greenhorn
Posts: 12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

The value of remoteHost should be ...


Ok, but what was its value when the exception happened?

The print out (posted messages) should show the values.  What did postMessage() output?



This is the message it gave me: "CONNECTING TO /127.0.0.1:51155 ON PORT 51155"

But I think I just fixed the problem. When I added in the new constuctor ConnectionHandler(Socket socket), I set the default ConnectionState to "Connecting" which is why it kept trying to execute the "socket = new Socket(remoteHost, port);" line. When I commented out the line of code that set that ConnectionState, it let my clients connect to the server. But in turn it brought up some more problems that wouldn't really have anything to do with my initial question
 
Logan Jones
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah so I got the connection problem fixed, and now I'm just getting problems with the JavaFX. I really appreciate you guys helping me out. and would love if you wanted to stick around and help me some more with this problem too, but I completely understand if you can't. Thanks again!
 
Ron McLeod
Saloon Keeper
Posts: 2270
290
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go ahead and create a new thread in the JavaFX forum
 
Logan Jones
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:Go ahead and create a new thread in the JavaFX forum


Will do! Thanks again for the help!
 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!