Java chat program giving me Connection Refused [duplicate]

寵の児 提交于 2019-12-12 05:39:45

问题


I am trying to build a java chat program. I have 7 classes for server and client altogether.

My errors are as follows when I run any class

    Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 192.168.56.1; nested exception is: 
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at java.rmi.Naming.rebind(Unknown Source)
    at ChatServerDriver.main(ChatServerDriver.java:10)
    Caused by: java.net.ConnectException: Connection refused: connect
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 sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
... 7 more

Here is my ChatServerDriver class

   import java.net.MalformedURLException;
   import java.rmi.Naming;
   import java.rmi.RemoteException;


   public class ChatServerDriver {

public static void main(String[] args) throws RemoteException, MalformedURLException{

    Naming.rebind("RMIChatServer", new ChatServer());

}

}


回答1:


You haven't started the RMI Registry.



来源:https://stackoverflow.com/questions/29991295/java-chat-program-giving-me-connection-refused

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!