This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes rmi over sockets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "rmi over sockets" Watch "rmi over sockets" New topic
Author

rmi over sockets

Yanick Labelle
Ranch Hand

Joined: Dec 29, 2003
Posts: 50
Hi, just a word, I had the application working perfectly well with sockets... (UrlyBird...)

When it was time to write the choices.txt document, I had simply no valid justifications for using sockets and not rmi. In fact, my only justification was that sockets are faster and that I didn't want to learn rmi (speed is not a requirement for the certification).

Then, I re-read the hitch hiker's guide to SCJD... don't panic!
(real name: The sun certified java developper exam with j2se 1.4.)
It is said that for the certification, for most people, it is easier and safer to use RMI instead of sockets. You don't have to create a custom communication protocol and a multithread server.

For this reason, Last weekend I changed my project and it now uses rmi. I still have some tests to make on locking and thread safety, but it seams to work really well. I feel much more confortable defending this choice than sockets.

Some questions:
I tried to use a custom port (other than 1099), it doesn't seems to work well... I'm thinking about always using the default port and not let the user choose it. What do you think?

Also, the certification document sais that rmi over http is not permited. It seems that when rmi can't open a connection on the default port, it falls back to http. How can one block that behavior, and guaranty that rmi will really not use http?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11277
    
  59

Hi Yanick,

When it was time to write the choices.txt document, I had simply no valid justifications for using sockets and not rmi. In fact, my only justification was that sockets are faster and that I didn't want to learn rmi (speed is not a requirement for the certification).


It is very good to see that you have looked at your justification critically. There are other reasons why you might want to use Sockets (care to comment Phil ), but now that you have learnt RMI you can make a more valid judgement based on which one works best for you.

Having said that, the justification that you "didn't want to learn xxx" can be a very valid justification in real life, especially when you have deadlines for projects.


I tried to use a custom port (other than 1099), it doesn't seems to work well... I'm thinking about always using the default port and not let the user choose it. What do you think?


I think it would be better for you to investigate the problems with other ports - it should work exactly the same no matter what port you use. And you really should not say in your design decissions document that other ports don't work or the examiner will go looking for problems with that part of your code.

From a real world perspective I do not like the combination of:
  • No security manager
  • Starting the registry programattically
  • Forcing the port to 1099


  • When you have all three cases, it means that you can only ever have one "server" application on any given machine.

    Having said that, I know that many people have passed with very good marks while forcing port 1099.

    Also, the certification document sais that rmi over http is not permited.


    Hmmm, my instructions only have "You must not require the use of an HTTP server" - not quite the same thing as saying you cannot use the HTTP protocol.

    The main reason for having a HTTP server is to have dynamically downloadable code (and there is a separate prohibition on that). But RMI can be tunelled through HTTP even without the presence of a HTTP server.

    But the answer to your question is: don't panic. By default your application will work correctly.

    Regards, Andrew


    The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
    Yanick Labelle
    Ranch Hand

    Joined: Dec 29, 2003
    Posts: 50
    Hi, thanks for the response!

    The ports other than 1099 now works.
    There is nothing to fear about rmi over http...
    The locking mecanism seems to react exactly like I expected.

    I have some questions about the 3 points that you said:

    I have no security manager but the certification document sais:
    " You must not require the installation of a security manager. "
    So, I don't have any reference to a security manager anywhere in my code.

    I start the registry in my code, while starting the server. (What is wrong with starting the registry in the program?)
    Philippe Maquet
    Bartender

    Joined: Jun 02, 2003
    Posts: 1872
    Hi Yanick,

    Andrew:
    It is very good to see that you have looked at your justification critically. There are other reasons why you might want to use Sockets (care to comment Phil ), but now that you have learnt RMI you can make a more valid judgement based on which one works best for you.


    Yanick:
    I feel much more confortable defending this choice [(RMI)] than sockets.


    I understand that. The main problem with sockets is that the main arguments in favour of them (performance, scalability (or anyway control over it), ...) suppose a solid sockets implementation which soon becomes overkill for the scope of this assignment. It can be challenging though, and quite interesting as a learning experience. In another SCJD life ( ) , I chose sockets and 100% finished my network layer. But when I'll start over with my assignment, I'll probably go with RMI myself. Now I've no regret because it was funny to code: thread pooling, support for multiformat marshalling (client A chooses to send and receive serialized objects, while client B receives them compressed), callback support, immediate client crashes detection (no lease as in RMI), etc. The problem with such an implementation is not to code it but to justify all your choices and ... document the code .

    Best regards,

    Phil.
    [ May 16, 2004: Message edited by: Philippe Maquet ]
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander

    Joined: Mar 28, 2003
    Posts: 11277
        
      59

    Hi Yanick,

    I start the registry in my code, while starting the server. (What is wrong with starting the registry in the program?)


    There is nothing wrong with it, and the instructions naturally lead us to do this. It is simple, it works, and the client does not have to do any special work to get it all running. Perfect.



    The potential problems come when the client wants a second application which also connects over RMI (Note: this discussion is just for information purposes - you do not need to concern yourself with this for this assignment).

    No other application can connect to the RMI Registry that you have started, because you do not have a security manager which might give the permission to connect (as per the instructions).

    To get around this you would have to:
  • Either start the RMI Registry separately and have both applications connect to it (this is preferred)
  • Or start another RMI Registry for each server application.


  • Unfortunately the way that most of the server applications are written for this assignment, the first option cannot be used. And if you force your applications to use port 1099 then the second cannot be used either.

    Regards, Andrew
    Yanick Labelle
    Ranch Hand

    Joined: Dec 29, 2003
    Posts: 50
    Hi, and thanks for your responses, with what you told me, I think that my code is ready to be sent to Sun for evaluation... The only things left are the user documentation and the choices.txt document. (Of course, I'm such a paranoid that I will re-check everything several times before sending it...)
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: rmi over sockets
     
    Similar Threads
    Sockets vs. RMI
    RMI Question
    Did SCJA yesterday
    URLyBird Lessons Learned
    Anybody interested in a sockets discussion ?