• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java RMI Server Down and Client ConnectException Connection refused  RSS feed

 
Jawad Hassan Khan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, This is my first post. I am newbie and self learning Java. Up till now, I was smooth and going fine with programming. From last one week, I am stuck at some point and feeling that I must seek help and came across coderanch. Now coming to the point.

I got a project of Chess Game which could be played over the LAN. I successfully build chess game and now want to make it work over LAN in multiplayer. I am stuck at RMI. I am new to RMI and build my first project which is sayHello, simples possible project. In server class, it is binding object with registry but crashes at the same point. Server class is as follows



Console is printing registry details after getting registry but unable to print Server Started. successfully binding object in registry which could be viewed in registry inspector. I also provided security policy file and also attached codebase. from Run Configuration, No exception is thrown on closing of class before completion. If I run client class, it gives me connection refused. error Client class is as follows.



It throws error
java.rmi.ConnectException: Connection refused to host: 192.168.1.3; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at com.sun.proxy.$Proxy0.printStatement(Unknown Source)
at Client.main(Client.java:11)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 7 more

I stuck at some point which is not logical. I am searching on google for this ConnectException, Possible reason is firewall. I am not behind any firewall, I using windows 8.1 . I think that Server crashing after rebind(....) point is linked with this.
Any help would be appreciated. Is there any better technology than RIM or alternative. I am stuck at this simple program for one week, In first few days, due to RMI Plugin, I was unable to do anything and finally got some clue and reinstalled the plugin. Now stuck at this.
 
Paul Clapham
Sheriff
Posts: 22520
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.rmi.ConnectException: Connection refused to host: 192.168.1.3; nested exception is:
java.net.ConnectException: Connection refused: connect


In your client, this message just means there is no server on 192.168.1.3 listening at the port you used, which appears to be 1099 (the RMI default). If your server crashes, that would explain why there is no server listening. At any rate you need to look on that machine and find out why the server isn't running. Or alternatively you need to fix the client to connect to a machine where a suitable server is running.
 
Jawad Hassan Khan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it means that problem is not with the code or anything else. It is solely with the machine.
 
Jawad Hassan Khan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I restarted the computer and it is working fine Now.

 
Jawad Hassan Khan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything was going fine. Again I am facing the same issue, It can be resolved by restarting the window. I think there must be some solution to this problem, I check out the error log shown in a different console view which is for the rmiregistry and showing error like



I think, I am unable to use socket. Can anyone help me on how to resolve this problem without windows restart.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "windows restart"? Whatever software you run on that machine should be in server mode (a.k.a. headless mode), and not open any windows. Otherwise it's liable to close whenever you log out.
 
Jawad Hassan Khan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Restarting windows mean, restarting computer (laptop). If I restart my laptop(Windows 8.1), Again it start working.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That should under no circumstances be necessary - restarting the server app should be sufficient.

If this is not a server-class machine, is there maybe a firewall involved that prevents or cuts connections?
 
Jawad Hassan Khan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a server machine, Actually app is simplest and basic one with just printing function so question of server or client machine doesn't arise. Starting question of thread is having the server and client class which I am executing. I tried several methods like cleaning registry and then restarting registry. Restarting eclipse, clean project etc. Just the solution of again getting server class to work properly is restarting laptop and then starting eclipse, starting rmi registry and then everything will work fine.
Couldn't find solution to this problem on Google, found this issue taken up in several forums but couldn't find the ultimate solution. Why server class which was performing well when we try to start registry and then suddenly It start crashing with this error message. This exception is not thrown in the server console. It is thrown in another view of the console which shows the working of "C:/Program Files/Java/jdk/bin/rmiregistry.exe localhost:1099".

May be this problem is with rmiregistry plugin. ???

 
Jawad Hassan Khan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Windows Firewall was active. I wasn't aware. Thanks for the help and support.

For Those having the same issue. Search for the Windows Firewall Application and turn off firewall.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!