port for underlying system?

Hi, i am currently writing my dissertation and have a client server architecture, i have written the rmi side of the project, however when i use the register and bind a service i have to specify the port which the server is hosting on as you would expect, but somewhere along the line java uses another port which must be open in order for it to work, my firewall initially blocked this warning me, but once i accepted it the program worked, until then it hung....

the code i use is :

//Server -

try{

reg = java.rmi.registry.LocateRegistry.createRegistry(port);

Naming.rebind("rmi://" + IPAddress +":" + port +"/TestServer",this);

}catch (AccessControlException a){

System.out.println("actions : " + a.getPermission().getActions());

System.out.println("name : " + a.getPermission().getName());

System.out.println("string : " + a.getPermission().toString());

}catch (MalformedURLException m){

System.out.println("Malformed : " + m.getMessage());

}

//Server -

//Client --

try{

Server_Interface serverside = (Server_Interface)Naming.lookup("rmi://" + ip +":" + port +"/TestServer");

//Do stuff from the server etc...

}catch(NotBoundException n){

System.out.println("NotBoundException : " + n.getMessage());

}catch(MalformedURLException m){

System.out.println("MalformedURLException : " + m.getMessage());

}catch(RemoteException e){

System.out.println("RemoteException : " + e.getMessage());

}

returnfalse;

//Client --

This all works fine, and specifying any port other than the one chosen for the server will not work, but i still need to know why or at least which port java is going to want as well? will it change etc?

Thanks for the help

Chris

[3018 byte] By [WastedYoutha] at [2007-11-26 18:17:40]
# 1

RMI uses a port for client-registry communication (typically 1099),

plus a port for client/server communication. If you don't specify the port for the latter, then it is chosen randomly. However I believe - now - that the code that "exports the server interface on startup now takes an optional port number. In other words, you can say what port you want to use.

bschauwejavaa at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 2
Thanks for the reponse, where abouts in the API would i find the class relating to exporting the server interface you mention?
WastedYoutha at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 3
java.rmi.server.UnicastRemoteObject
cooper6a at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 4

Then i take it you are referring to the contructor taking a port, i have a call to super proporgating the port number through as my class extends unicastRemoteObject. Does this have to be a different port to that which the registry is created on? is java simply seeing the clash and assigning an anon port?

WastedYoutha at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 5
I already told you it should not be the registry port.
bschauwejavaa at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 6
It can be the same port if the registry is running in the same JVM, as here.
ejpa at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 7

since i create the registry from the code, this means im using the same VM yeh? if so then how do i enforce the use of the same port, because currently it uses another one... i think the next thing ill try is to get the next unused port from my system and see if it matches the one thats being used as well as the registry...

Thanks for the help...

WastedYoutha at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 8

How can an unused port match a used port?

You can provide the port number to createRegistry() and also to super() when constructing your UnicastRemoteObject, or to UnicastRemoteObject.exportObject() if your server doesn't extend UnicastRemoteObject.

It should happen that way automatically too if you don't provide a port number. Are you using socket factories by any chance?

ejpa at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 9

i meant in a logical order... ie, check the next unused port then start the server and see if the one it uses is the same that was the next free on,...

however it was over 1000 i wouldnt think that all ports < 1000 are being used.

You say i can call super(port); and also createRegistry(port), i have said this is what i already do and it doesn't seem to be working...

WastedYoutha at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 10
If you specify the same port for the Registry and your remote object it will either use the same port for both as requested, or fail to create whichever of these you did last.When you say 'it doesn't seem to be working' what exactly do you mean? This is too vague to be useful.
ejpa at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 11

Sorry ill be a little more descriptive, the overall program DOES work, however specifying ports does not seem to yeild the desired results, ie: i call super(port) this should set up the port number for the data transmission for the RMI right?

i later call ....createRegistry(port)

which sets the registry running on the specified port, the latter is not the problem, trying to get the registry on any other port fails, however data is transmitted over the network on another port...

hope this is clear... There is no real rush for this, i basically need it to allow me to have a chance of trying my software at uni with their tight security...

Thanks Chris

WastedYoutha at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 12
What evidence do you have that data is transmitted over another port?
ejpa at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 13

because my firewall has to accept another port from the same machine, until this is accpeted the program waits...

but your right, it could be that the registry is using the new port and the data is sent over my defined port... but either way it seems to need 2.

No worries i dont think im gonna find out so ill have to live with it...

Thanks for the help anyways

WastedYoutha at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...
# 14
Until this is accepted by whom? I don't understand. If the firewall was preventing use of a port you would get an exception of some kind.
ejpa at 2007-7-9 5:51:17 > top of Java-index,Core,Core APIs...