Anyone here knowledgable on Java RMI?
I've got a headache on my case here - I didn't know much of RMI beforehand, so I took the project, issued remote interfaces for all the necessary classes and unicast them. Then the Client is given a stub of an object which containst all the necessary data - and the client can access all the data that that client can access by virtue of having that stub, plus a stub of the client's own user object stub.
On a LAN it works well enough. I realize that it's a pretty non-optimized solution, in fact even a shitty solution, but it works well on LAN. But when I run it on a server in the cloud, and try to connect to the server it lags like crazy, even though there's only 72ms of lag.
I think it's because exported RMI objects make the packets go back and forth, back and forth somehow. Seeing as how I've set the java.rmi.server.hostname of the server to it's wan-ip (behind a router) and my own on a wan-ip (behind a router) as well. This is causing timeouts and makes the project pretty much unusable.
I'm sorry for not being clear here. I'll explain the code a bit.
Server:
- the server sets the hostname to its WAN-ip
- server sets up the main object, which contains all other objects needed for operation, and exports it with unicast
- server creates a registry on port 1099
- server binds an object (which has a login and a register method) stub to a name
Client:
- client sets hostname to its WAN-ip (for the listeners)
- client locates the registry on port 1099 of the server's WAN ip
- client does a lookup for the object bound to the name set by the server
- client logs in and gets the stub for the main object, and through the interface has methods with which to execute commands on the server.
From there on it flows from one remote object to another, each exported on server side and sent via method of the previous object.
I think it's just looping on itself somehow. The datarate is really low, around 1 kb/s. But opon login, the client recieves an ILobby interface, a stub/proxy of the real lobby on the server side - but this takes almost 30s.
When the clients sends a message - the clients uses chat.sendmessage(IUser user, String message) - (the IUser is a stub of a user, originating from the server side).
The server makes a message out of it, and in the same method (sendmessage) sends a publish out to all the listeners. Each publish issued has its own thread, so the server doesn't hang here. But it still gets a timeout.
Can anyone explain to me what I'm doing that would cause this? Is RMI not made to be used in this way at all? Is RMI just not useable for connections between different networks? If any clarification is necessary let me know, kinda don't know where to start with explaining, since it's such a mess because of RMI.