I have set up RMI system successfully on local ubuntu srver.
Registry port 1099 and remote object export on 1100(fixed by calling super(1100))
Now I am trying to make it work on Ubuntu over internet with a public IP.
I could bind service properly with public ip.But the client applet is trying to connect to ubuntu server at random ports.
Below is the error thrown by client applet:

I have only 2 ports open on server, i.e., 1099(registry) and 1100(export). How can I fix ports in applet requests such that it does always connect server on same open port?

Another issue.
As I have bound service on public IP i.e. //public-ip:1099/ServiceName, a job running on server to send message to clinets is not able to make request to RMI service. public-ip URL does not work on same machine,i.e., server.Do you think I should use fixed socket factory?If so please give me code snippet and guide me how i can set it up.

//Exception
java.rmi.ConnectException: Connection refused to host: public-ip; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:128)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at $Proxy5.getUserID(Unknown Source)
at rmi.source.xxxxxx$JobScheduler.run(xxxxServerImpl.java:293)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 9 more

Thank you for your quick response.I did export object on server implementation (extending UnicastRemoteObject) contructor by calling super(1100) Also I have set java.rmi.server.hostname property with public IP on server as well as client applet.Did rebind on public IP But getting following exception now:
–
DanAug 30 '12 at 10:54

@Dan Are you getting that from inside or outside the LAN? Or both? RMI's possibly invalid presumption is that there is a 'most public' IP address that everybody can use, hence the java.rmi.server.hostname design.
–
EJPAug 30 '12 at 21:53

client is outside LAN.Using windows client over different internet connection with a public-ip.I am trying to connect from a pc in this windows LAN to Ubuntu rmi server on different internet connection. I have port forwarded both 1099 and 1100(fixed exported port) on this windows client NAT too.Windows client pc's have fixed IP's 192.168.1.X and public IP 122.166.X.YYY I also tried by giving hostname in clinet applet these ip addresses.Still no luck.Where am I gone wrong? @EJP
–
DanAug 31 '12 at 4:37

java.rmi.server.hostname is set at the server.
–
EJPAug 31 '12 at 12:27