Java RMI - Client Timeout

前端 未结 4 1563
走了就别回头了
走了就别回头了 2020-11-30 05:53

I\'m building a Distributed System using Java RMI and it must support a server loss.

If my client is connected to a Server using RMI, if this server goes down (cable

4条回答
  •  天涯浪人
    2020-11-30 06:43

    For socket read timeout, you can set your own factory like this,

               RMISocketFactory.setSocketFactory( new RMISocketFactory()
                {
                    public Socket createSocket( String host, int port )
                        throws IOException
                    {
                        Socket socket = new Socket();
                        socket.setSoTimeout( timeoutMillis );
                        socket.setSoLinger( false, 0 );
                        socket.connect( new InetSocketAddress( host, port ), timeoutMillis );
                        return socket;
                    }
    
                    public ServerSocket createServerSocket( int port )
                        throws IOException
                    {
                        return new ServerSocket( port );
                    }
                } );
    

提交回复
热议问题