Applet/Servlet communication: what are your thoughts on this?
I've been reading up on Applet/Servlet communication ( http://www.unix.org.ua/orelly/java-ent/servlet/ch10_01.htm ) in the hopes of someday updating my very strange chatroom (an amalgam of JSP, PHP, servlets, XML and stuff I can't even identify), and I noticed that there are several methods for passing data between client applet and remote servlet including:
1) HTTP
2) non-HTTP Socket
3) RMI
I also noticed the advantages and disadvantages of using each one and honestly, I can't decide what is best and what should I avoid.
The basic premise is a simple messaging chatroom applet with HTML-enabled messages (with limited HTML capability for obvious security reasons) passed onto a remote host servlet back and forth until you're done.
What experiences might you have had that would ensure that the best-practice method would be either HTTP, non-HTTP Socket or RMI?
Just wondering at this point, nothing implemented as of yet
Thanks
Phil
> 1) HTTP
Easiest way to go, since most Servlet's are implemented as HttpServlet. Not the absolute most efficient protocol (in terms of latency) but very quick to develop and straightforward.
> 2) non-HTTP Socket
The most efficient way to go (other than NIO). However, you would be writing a custom protocol. Optimization would be up to you, but the system could be far more efficient than RMI or HTTP. Then again, maintaining and documenting the protocol might end up costing more in the long run. You also would not be taking advantage of open standards. As always, there are trade-offs.
> 3) RMI
The least desirable option, IMO. Java serialization is used to send POJO's over the wire. For simple messages (such as a series of strings), this is way, way overkill. For a complex message object, the performance will probably be better than XML-RPC or a SOAP call. But those have the advantages of open standards. This would be my third-place pick.
To your options above, you may consider JAXB (to marshall and unmarshall XML to POJO's) or a proper web service ala SOAP (could be REST as well).
- Saish
> BTW you can't do RMI to a servlet. You can run an RMI
> server inside a servlet but then it's not really a
> servlet any more, it's just a dummy framework for
> hosting an RMI server.
I'm afraid I don't understand why it is no longer a servlet in this case, please explain, thanx
> A servlet is a mini-server that receives HTTP requests and is hosted by a servlet container.
That is a HTTP servlet. However, other types of servlet are certainly possible. That is why HttpServlet implements Servlet.
Granted, it might be lipstick on a pig, but it would still "count" in my book as a Servlet if the OP implements the interface. :^)
- Saish