The usual/Practical approach is to write a Servlet to handle the messages in the server side, and use a browser or something like the Apache HTTP client library to act like a sever. With this, you can use standard SSL/TLS to provide secure access.
You could, of course, use RMI and a suitable cryptography library.
sorry to ask this but could you point me to an example, or keywords to type in google to find the examples. I am not able to google a particular example.