Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RMI, old Sockets, new Channels? Help!!!



We did this on a project for the department of immigration - a swing app connecting to a remote database.

Our solution was to put serialised method calls (ie, an object containing method name and arguments) into a HTTP request, and have a servlet at the other end unwrap the call and invoke the server.

Doing this allowed us to get through proxies and firewalls, because rather than dealing with sockets, we were dealing with HTTP requests and webservers. However, it's a pretty heavyweight solution.

For what you describe: (to say, "add a new question to the database" or "give me a list of all the subjects", "someone changed the list of subjects" or "please log in"), RMI is the way to go if you are just running on a local network and getting a socket connection is not a problem. Doing this allows you to ignore keeping sockets open and stuff like that. To do "two way" calls (the server can asynchronously call the client):

0) The server sets up an RMI server object
1) The client must set up an object to act as an RMI server. This is the "callback" object.
2) The client locates the server RMI object (this is the tricky bit)
3) The client logs into the server, passing it's callback as a parameter (as well as login info, typically).
4) The server passes back to the client an object implementing the interface that the client actually wants
4) The server keeps track of client sessions, occasionally sending them "are you still alive?" calls.


To maintain "state", calls from the client to the server need to contain a reference to the session. There are a couple of ways to do this: the server can build an RMI object for each connected client (the easy way), or it can have one RMI server which all the clients use (the not-so-easy way).

Note that on the client side, calls received on the "callback" object are not on the swing thread, so you will need to do a SwingUtilities.invokeLater() to handle them.

Would you like some sample code?

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.