Posted by turbogeek
on August 10, 2003 at 11:22 PM PDT
Learn how you can write a remote desktop application with Java and JXTA. Or: How to amaze your friends by reading the manual.
Sometimes you do something that surprises people. Jaws drop and wonder is seen in your friends eyes. You too can tap into these secrets of the ancients. See a source of hidden knowledge, known only to select few. Answer the riddle of the Sphinx, just by reading the manual.
A little knowledge, creativity and some imagination and you can change the way people think. I have just recently done just that. I do it a lot because I have a habit of reading the manual and exploring how I can apply what I have read in ways the authors have not expected. Its a bad habit from school where I was bored with dry assignments, so I twisted them to be interesting to me, rather than the teacher. Yes, I was a rebel
What I have done recently is to mix a couple disassociated things to create something not really intended by the designers. The first is Robot class in the java.awt package. This is certainly one of those read-the-manual things. You may have not heard of the Robot class. Robot was probably added to Java in 1.4 to help with testing. First it can capture an image of the entire desktop or just a part of it. This is quite a cool considering that in the past Java was limited to its own windows. The second, and very surprising feature is that it can send mouse and keyboard events to the operating system. In effect, controlling the entire desktop. Quite a departure from what you thought Java could do eh?
A Remote Possibility
Of course what this meant to me was that I could do more than capture the desktop or control things for a test. This meant I could control the computer from a Java application. Specifically I wanted to do it remotely. More specifically, using JXTA.
JXTA-Remote-Desktop was born! No need to dig up bodies and piece the monster together. Just pick up a couple of pieces and read the manuals. The Jr. Frankenstein kit.
Open Source A Me
What is JXTA-Remote-Desktop(JRD)? First it is open source and hosted here at java.net. Its a simple implementation of the remote desktop idea, like PC Anywhere, Go To My PC, or VNC. It is written in 100% Java using JXTA as a transport. The key difference from the competitors (it is hard to compete with VNC because it is free), is that JRD can connect any two PC's even if there is DHCP, a firewall, or a NAT**.
JXTA's P2P network uses other generic computers to act as middlemen for HTTP tunneling and relay of messages. This is not a big security hole because the computer behind the firewall must be a willing party to the communication, just like other HTTP tunneling applications. JXTA also has its own addressing scheme so NAT and DHCP are not a problem.
JXTA is certainly not the best choice (message rather than stream based, and it has unpredictable data rates), but it is the only choice for this type of application. Think about your average PC. You can't get to it with a URL because it has no web address. You can't depend on its IP address because it changes. And theres usually a NAT or firewall preventing direct access. JXTA lets you access almost any connected PC no matter what its current IP address or topology.
How good is JRD? Well, it is not as good as VNC yet. There still needs to be a little work to get the screenshots to be a little more efficient. Most remote applications use the native OS to get just what changes on the screen while JRD is limited to screen shots. JRD can become better through a combination of compression and differencing techniques similar to Internet video. The I/O of mouse and keyboard are delayed quite a bit so the user does not get too far ahead of the screen updates.
JXTA-Remote-Desktop is getting closer to being a viable application. The code works and there is even a multiplatform installer. I will also have an article at P2PJournal.com soon to explain the code. Since it is open source, I am looking for help to improve it. High on my wish list is better video differencing. I challenge you to look at the code and come up with an innovating solution to this devilish problem.
More to come! Up next, running Java and JXTA applications on an Apple Macintosh!
** NAT is an acronym for Network Address Translation. Most cable modems and DSL routers implement NAT. A NAT prevents anyone from directly contacting a PC from outside your home network.