RMI: Connection refused to host - Editing /etc/hosts and setProperty() not working
<p>I know that this question has been asked before but the answers I found so far did not help. I tried editing my /etc/hosts-file by adding the line</p>

<pre><code>127.0.0.1    java.rmi.server.hostname
</code></pre>

<p>Next, I tried adding </p>

<pre><code>System.setProperty("java.rmi.server.hostname","127.0.0.1");
</code></pre>

<p>to my code (also tried with my "external" IP-Address). However, I keep getting this error:</p>

<pre><code>java.rmi.ConnectException: Connection refused to host: 192.168.178.22; nested exception is: 
    java.net.ConnectException: Connection refused
    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.newCall(UnicastRef.java:342)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at java.rmi.Naming.rebind(Naming.java:177)
</code></pre>

<p>Here is my server's code:</p>

<pre><code>public class CounterServer {
    public static void main(String args[]) {
        try {
            System.setProperty("java.rmi.server.hostname","192.168.178.22");

            LocateRegistry.createRegistry(4711);

            ICounter counter = new Counter();
            Naming.rebind("Counter", counter);
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
}
</code></pre>

<p>Any ideas how I can get this fixed? I am running on a Mac OSX!</p>