package util.rmi import java.net.MalformedURLException import java.rmi.Naming import java.rmi.NotBoundException import java.rmi.Remote import java.rmi.RemoteException class Client(private val handler: () -> Unit) { fun start() = try { handler() } catch (e: NotBoundException) { System.err.println("Request obect not bound $e") } catch (e: MalformedURLException) { System.err.println("Wrong URL $e") } catch (e: RemoteException) { System.err.println("Network or Server Error $e") } catch (e: Exception) { System.err.println("Generic Error $e") } companion object { fun lookup(name: String, port: Int = 4242): Remote = Naming.lookup("rmi://localhost:$port/$name") } }