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

Printing to the terminal in a encoding neutral manner

c locale fwrite utf

I would like to print a string to the screen regardless of its encoding (UTF-8,16,32). This string is represented in a char array so I need to ignore null bytes and carry on printing to stdout; thi...

Jquery Rest communication with WCF 3.5

jquery wcf rest

I'm testing the basics for exchanging rest messages between a mvc site and a WCF 3.5 service.

How to composite the view hierarchy to enhance animation performance?

iphone ios performance ipad core-animation

I have several views with a lot of subviews, and during animation the performance is very poor.