2013-04-12 1 views
0

Я хочу построить сервер RMI, я попытался как этотJava RMI Исключение

package first_project; 

import java.rmi.Naming; 
import java.rmi.RemoteException; 
import java.rmi.server.UnicastRemoteObject; 
import java.util.ArrayList; 


public class Server extends UnicastRemoteObject implements ServerInterface { 

    // list for know users 
    protected ArrayList<ClientInterface> clients = new ArrayList<ClientInterface>(); 


    public Server() throws RemoteException {} 

    //logged in clients get a notification that a new user has joined the chat 
    // remote reference to the new client is added to the ArrayList. 
    public void login(ClientInterface client, String nickname) throws RemoteException { 
     broadcastMessage("--> " + nickname + " is entering the chatroom", ""); 
     clients.add(client); 
    } 

    // used for broadcasting an incoming message 
     // and the nickname of its sender to all currently logged in clients . 
     //remote call of the method getMessage which is 

    public void broadcastMessage(String message, String nickname) throws RemoteException { 
     for (int i = 0; i < clients.size(); i++) { 
      ClientInterface c = clients.get(i); 
      try { 
       c.getMessage(message, nickname); 
      } catch (RemoteException e) { 

          logout(c); 
        i = i - 1; 
      } }} 

     //remove user 
    public void logout(ClientInterface client) { 
     clients.remove(client); 
    } 


    public static void main(String[] args) { 
     try { 
      Naming.rebind("Server", new Server()); 
      System.out.println("Server is ready"); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

, но я не знаю, почему я получил это исключение:

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:601) 
     at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198) 
     at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184) 
     at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322) 
     at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source) 
     at java.rmi.Naming.rebind(Naming.java:160) 
     at first_project.Server.main(Server.java:47) 
Caused by: java.net.ConnectException: Connection refused: connect 
     at java.net.PlainSocketImpl.socketConnect(Native Method) 
     at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) 
     at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) 
     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) 
     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) 
     at java.net.Socket.connect(Socket.java:519) 
     at java.net.Socket.connect(Socket.java:469) 
     at java.net.Socket.<init>(Socket.java:366) 
     at java.net.Socket.<init>(Socket.java:180) 
     at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22) 
     at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128) 
     at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595) 
     ... 6 more 

, что я делаю неправильно, пожалуйста?

заранее заблаговременно

+0

Похоже у вас есть аналогичные проблемы, как [это] [1] [1]: HTTP : //stackoverflow.com/questions/1823305/rmi-connection-refused-with-localhost –

+0

@ Seid.M Нет, это не так. OP в этом потоке, по крайней мере, пытается запустить реестр. Об этом нет никаких доказательств. – EJP

ответ

0

У вас начался реестр. Попробуйте после запуска системного реестра
начала rmiregistry для окон
rmiregistry & для Linux/Unix

+0

Точно. @Downvoter обратите внимание. +1 – EJP