Remote method invocation port in use

I have created a Server, Client kind of program with RMI. But whenever I run my Server after starting the rmiregistry from command prompt, the port already in use error is thrown. Its only me who started the rmiregistry. I have checked it from netstat.

Server Code:

public class Server implements Runnable, Linker{

private static Server server = null;
    private static Linker l = null;
    private String name = null;
    public Server(){}

    public void setName(String name){ = name;
    public String getName(){
        return name;               
    public void run(){

    public static void createStub(){
            server = new Server();
            l = (Linker) UnicastRemoteObject.exportObject(server, 1099);

            Registry registry = LocateRegistry.getRegistry();
            registry.bind("Link", l);
        catch(Exception e){
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Thread t = new Thread(server);


Client Code:

public class Client implements Runnable{

private Scanner sc = new Scanner(;
    private Linker linker = null;

    public void loadStub(){
            Registry registry = LocateRegistry.getRegistry(1099);
            linker = (Linker) registry.lookup("Link");

        }catch(Exception e){

    public void run(){
        String ip = null;
        while(sc.hasNext()&&!(ip = sc.nextLine()).equalsIgnoreCase(":q")){
            try {
            } catch (RemoteException e) {
                // TODO Auto-generated catch block

    public static void main(String...args){
        Client client = new Client();
        Thread t = new Thread(client);


java.rmi.server.ExportException: Port already in use: 1099; nested exception is: Address already in use: JVM_Bind


The rmiregistry is using port 1099 in its process so you can't use it in yours. Either:

  1. Start the registry in the same process, via LocateRegistry.createRegistry() (preferred).
  2. Export your object on a different port.
  3. Start the rmiregistry on a different port other than 1099.

If you using MAC OS, you can stop port

You need find the PID: lsof -i :1099

And then kill the port: kill -9 PID_number

Use this Server code -

Registry registry = null;
try {
    registry = LocateRegistry.getRegistry(52365);//use any no. less than 55000
    // This call will throw an exception if the registry does not already exist
catch (RemoteException e) { 
    registry = LocateRegistry.createRegistry(52365);

Need Your Help

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.