I am trying to do RMI Server-Client communication, but I get these exceptions when I try to run client:

java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1371 connect,resolve)
	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
	at java.security.AccessController.checkPermission(AccessController.java:546)
	at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
	at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
	at java.net.Socket.connect(Socket.java:519)
	at java.net.Socket.connect(Socket.java:475)
	at java.net.Socket.<init>(Socket.java:372)
	at java.net.Socket.<init>(Socket.java:186)
	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)
	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.lookup(Unknown Source)
	at Client.<init>(Client.java:47)
	at Client.main(Client.java:104)

Here is how I implement Server class:

System.setSecurityManager(new RMISecurityManager());

		try {
			address_ = (InetAddress.getLocalHost()).toString();
		} catch (UnknownHostException e) {
			e.printStackTrace();
			System.exit(1);
		}
		port_ = 1371;

		try {
			registry_ = LocateRegistry.createRegistry(port_);
			registry_.rebind("MyServer", this);
		} catch (RemoteException e) {
			e.printStackTrace();
			System.exit(1);
		}

		System.out.println("Server succesfully started...");
		System.out
				.println("{Address = " + address_ + ", port = " + port_ + "}");
		System.out.println("Waiting for tasks...");

This is part of my Client class:

System.setSecurityManager(new RMISecurityManager());

		System.out.println("Trying to connect to " + SERVER_ADDRESS + " via "
				+ PORT);

		try {
			
			registry_ = LocateRegistry.getRegistry(SERVER_ADDRESS, PORT);
			server_ = (Communication) (registry_.lookup("MyServer"));
		} catch (RemoteException e) {
			e.printStackTrace();
			System.exit(1);
		} catch (NotBoundException e) {
			e.printStackTrace();
			System.exit(1);
		}

		System.out.println("Success");

This is where I get exceptions:
Line 47: server_ = (Communication) (registry_.lookup("MyServer"));

Can somebody help me to fix this.
Thanks, I appreciate your help, if you need more code let me know.

Recommended Answers

All 2 Replies

The port 1371 may be already in use try a random port 13371 ,etc .

I have changed it to other port and I still get this exception

Thanks for the reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.